From 7fa1eb17f907fe5c3878a331960cdd59217db43c Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 25 Aug 2014 16:26:58 +0700 Subject: fixed correctness issue in the CivicDuty badge awards and allowed to edit comments by high reputation users --- askbot/management/commands/askbot_award_badges.py | 28 +++++++++++++++++++++++ askbot/models/__init__.py | 4 ++++ askbot/models/badges.py | 12 ++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 askbot/management/commands/askbot_award_badges.py diff --git a/askbot/management/commands/askbot_award_badges.py b/askbot/management/commands/askbot_award_badges.py new file mode 100644 index 00000000..3f8132b7 --- /dev/null +++ b/askbot/management/commands/askbot_award_badges.py @@ -0,0 +1,28 @@ +"""WARNING: +This command is incomplete, current awards only +Civic Duty badge +""" + +from askbot.models import badges +from askbot.models import User +from askbot.models import Vote +import datetime +from django.core.management.base import NoArgsCommand + +class Command(NoArgsCommand): + def handle_noargs(self, *args, **kwargs): + now = datetime.datetime.now() + for user in User.objects.all(): + try: + #get last vote + vote = Vote.objects.filter(user=user).order_by('-id')[0] + except IndexError: + #user did not vote + continue + else: + cd = badges.CivicDuty() + cd.consider_award( + actor=user, + context_object=vote.voted_post, + timestamp=now + ) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index dd992c99..6919ebeb 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -863,6 +863,10 @@ def user_assert_can_edit_comment(self, comment = None): else: return + if not (self.is_blocked() or self.is_suspended()): + if self.reputation >= askbot_settings.MIN_REP_TO_EDIT_OTHERS_POSTS: + return + error_message = _( 'Sorry, but only post owners or moderators can edit comments' ) diff --git a/askbot/models/badges.py b/askbot/models/badges.py index 44eda0c3..58a4a978 100644 --- a/askbot/models/badges.py +++ b/askbot/models/badges.py @@ -84,7 +84,9 @@ class Badge(object): return dict(const.BADGE_TYPE_CHOICES).get(self.level) def award(self, recipient = None, context_object = None, timestamp = None): - """do award, the recipient was proven to deserve""" + """do award, the recipient was proven to deserve, + Returns True, if awarded, or False + """ from askbot.models.repute import Award if self.multiple == False: if recipient.badges.filter(slug = self.key).count() != 0: @@ -244,10 +246,12 @@ class CivicDuty(Badge): def consider_award(self, actor = None, context_object = None, timestamp = None): - if context_object.post_type not in ('question', 'answer'): + + obj = context_object + if not (obj.is_question() or obj.is_answer() or obj.is_comment()): return False - if actor.votes.count() == askbot_settings.CIVIC_DUTY_BADGE_MIN_VOTES: - return self.award(actor, context_object, timestamp) + if actor.votes.count() >= askbot_settings.CIVIC_DUTY_BADGE_MIN_VOTES: + return self.award(actor, obj, timestamp) class SelfLearner(Badge): def __init__(self): -- cgit v1.2.3-1-g7c22