from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser
from django.db.models import Q
-try:
- from hashlib import md5
-except:
- from md5 import new as md5
+
+from forum.settings import TRUNCATE_LONG_USERNAMES, TRUNCATE_USERNAMES_LONGER_THAN
import string
from random import Random
from django.utils.translation import ugettext as _
import logging
-QUESTIONS_PER_PAGE_CHOICES = (
-(10, u'10'),
-(30, u'30'),
-(50, u'50'),
-)
-
class AnonymousUser(DjangoAnonymousUser):
+ reputation = 0
+
def get_visible_answers(self, question):
return question.answers.filter_state(deleted=False)
def can_vote_down(self):
return False
+
+ def can_vote_count_today(self):
+ return 0
def can_flag_offensive(self, post=None):
return False
def can_convert_to_comment(self, answer):
return False
+
+ def can_convert_to_question(self, answer):
+ return False
+
+ def can_convert_comment_to_answer(self, comment):
+ return False
def can_accept_answer(self, answer):
return False
@property
def decorated_name(self):
+ username = self.username
+
+ if len(username) > TRUNCATE_USERNAMES_LONGER_THAN and TRUNCATE_LONG_USERNAMES:
+ username = '%s...' % username[:TRUNCATE_USERNAMES_LONGER_THAN-3]
+
if settings.SHOW_STATUS_DIAMONDS:
if self.is_superuser:
- return u"%s \u2666\u2666" % self.username
+ return u"%s \u2666\u2666" % username
if self.is_staff:
- return u"%s \u2666" % self.username
+ return u"%s \u2666" % username
return self.username
sub_settings = SubscriptionSettings(user=self)
sub_settings.save()
- def get_absolute_url(self):
- return self.get_profile_url()
-
def get_messages(self):
messages = []
for m in self.message_set.all():
today = datetime.date.today()
return self.actions.filter(canceled=False, action_type="flag",
action_date__gte=(today - datetime.timedelta(days=1))).count()
-
+
+ def can_vote_count_today(self):
+ votes_today = settings.MAX_VOTES_PER_DAY
+
+ if settings.USER_REPUTATION_TO_MAX_VOTES:
+ votes_today = votes_today + int(self.reputation)
+
+ return votes_today
+
@true_if_is_super_or_staff
def can_view_deleted_post(self, post):
return post.author == self
def can_delete_comment(self, comment):
return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS)
+ def can_convert_comment_to_answer(self, comment):
+ return (comment.parent.node_type in ('question', 'answer')) and (self.is_superuser or self.is_staff or (
+ self == comment.author) or (self.reputation >= int(settings.REP_TO_CONVERT_COMMENTS_TO_ANSWERS)))
+
def can_convert_to_comment(self, answer):
return (not answer.marked) and (self.is_superuser or self.is_staff or answer.author == self or self.reputation >= int
(settings.REP_TO_CONVERT_TO_COMMENT))
#auto_subscribe_to
all_questions = models.BooleanField(default=False)
all_questions_watched_tags = models.BooleanField(default=False)
- questions_asked = models.BooleanField(default=True)
- questions_answered = models.BooleanField(default=True)
- questions_commented = models.BooleanField(default=False)
questions_viewed = models.BooleanField(default=False)
#notify activity on subscribed