X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/b8f3a2323d03384198863e35d6467a8624a2e31a..5283989ac4276aeef30e04acfcd7d167a3710a1f:/forum/models/user.py diff --git a/forum/models/user.py b/forum/models/user.py index ff7bef1..31f4e19 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -1,5 +1,4 @@ from base import * -from forum import const 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 @@ -27,7 +26,7 @@ class UserManager(CachedManager): class AnonymousUser(DjangoAnonymousUser): def get_visible_answers(self, question): - return question.answers.filter(deleted=None) + return question.answers.filter_state(deleted=False) def can_view_deleted_post(self, post): return False @@ -56,12 +55,21 @@ class AnonymousUser(DjangoAnonymousUser): def can_delete_comment(self, comment): return False + def can_convert_to_comment(self, answer): + return False + def can_accept_answer(self, answer): return False def can_edit_post(self, post): return False + def can_wikify(self, post): + return False + + def can_cancel_wiki(self, post): + return False + def can_retag_questions(self): return False @@ -142,7 +150,7 @@ class User(BaseModel, DjangoUser): return mark_safe(profile_link) def get_visible_answers(self, question): - return question.answers.filter(deleted=None, in_moderation=None) + return question.answers.filter_state(deleted=False) def get_vote_count_today(self): today = datetime.date.today() @@ -151,12 +159,9 @@ class User(BaseModel, DjangoUser): def get_reputation_by_upvoted_today(self): today = datetime.datetime.now() - sum = self.reputes.filter( - models.Q(reputation_type=TYPE_REPUTATION_GAIN_BY_UPVOTED) | - models.Q(reputation_type=TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED), - reputed_at__range=(today - datetime.timedelta(days=1), today)).aggregate(models.Sum('value')) - - if sum.get('value__sum', None) is not None: return sum['value__sum'] + sum = self.reputes.filter(reputed_at__range=(today - datetime.timedelta(days=1), today)).aggregate(models.Sum('value')) + #todo: redo this, maybe transform in the daily cap + #if sum.get('value__sum', None) is not None: return sum['value__sum'] return 0 def get_flagged_items_count_today(self): @@ -205,6 +210,9 @@ class User(BaseModel, DjangoUser): def can_delete_comment(self, comment): return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS) + 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)) + @true_if_is_super_or_staff def can_accept_answer(self, answer): return self == answer.question.author @@ -212,7 +220,15 @@ class User(BaseModel, DjangoUser): @true_if_is_super_or_staff def can_edit_post(self, post): return self == post.author or self.reputation >= int(settings.REP_TO_EDIT_OTHERS - ) or (post.wiki and self.reputation >= int(settings.REP_TO_EDIT_WIKI)) + ) or (post.nis.wiki and self.reputation >= int(settings.REP_TO_EDIT_WIKI)) + + @true_if_is_super_or_staff + def can_wikify(self, post): + return self == post.author or self.reputation >= int(settings.REP_TO_WIKIFY) + + @true_if_is_super_or_staff + def can_cancel_wiki(self, post): + return self == post.author @true_if_is_super_or_staff def can_retag_questions(self): @@ -239,6 +255,11 @@ class User(BaseModel, DjangoUser): def can_upload_files(self): return self.reputation >= int(settings.REP_TO_UPLOAD) + def check_password(self, old_passwd): + self.__dict__.update(self.__class__.objects.filter(id=self.id).values('password')[0]) + return DjangoUser.check_password(self, old_passwd) + + class Meta: app_label = 'forum' @@ -248,10 +269,10 @@ class SubscriptionSettings(models.Model): enable_notifications = models.BooleanField(default=True) #notify if - member_joins = models.CharField(max_length=1, default='n', choices=const.NOTIFICATION_CHOICES) - new_question = models.CharField(max_length=1, default='d', choices=const.NOTIFICATION_CHOICES) - new_question_watched_tags = models.CharField(max_length=1, default='i', choices=const.NOTIFICATION_CHOICES) - subscribed_questions = models.CharField(max_length=1, default='i', choices=const.NOTIFICATION_CHOICES) + member_joins = models.CharField(max_length=1, default='n') + new_question = models.CharField(max_length=1, default='d') + new_question_watched_tags = models.CharField(max_length=1, default='i') + subscribed_questions = models.CharField(max_length=1, default='i') #auto_subscribe_to all_questions = models.BooleanField(default=False)