X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/b8f3a2323d03384198863e35d6467a8624a2e31a..160d1ba325585d57e013437f68b06bc90ac341d0:/forum/models/user.py diff --git a/forum/models/user.py b/forum/models/user.py index ff7bef1..a3714ae 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,18 @@ 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_retag_questions(self): return False @@ -142,7 +147,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 +156,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 +207,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 +217,11 @@ 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_retag_questions(self): @@ -248,10 +257,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)