From b7bd197a889546e6d8a1c8bb093d2da2b1b8fcb9 Mon Sep 17 00:00:00 2001 From: jordan Date: Tue, 4 Jan 2011 11:43:52 +0000 Subject: [PATCH] Added an option to allow users with higher reputation vote more than the users with a lower one. The user reputation is added to the MAX_VOTES_PER_DAY option. This option can be moderated from the OSQA administration. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@667 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/user.py | 13 ++++++++++++- forum/settings/email.py | 2 +- forum/settings/voting.py | 4 ++++ forum/views/commands.py | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/forum/models/user.py b/forum/models/user.py index 8f2ccd0..8ef201d 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -33,6 +33,9 @@ class AnonymousUser(DjangoAnonymousUser): def can_vote_down(self): return False + + def can_vote_count_today(self): + return 0 def can_flag_offensive(self, post=None): return False @@ -238,7 +241,15 @@ class User(BaseModel, DjangoUser): 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 diff --git a/forum/settings/email.py b/forum/settings/email.py index 2a46e29..4c9486a 100644 --- a/forum/settings/email.py +++ b/forum/settings/email.py @@ -11,7 +11,7 @@ EMAIL_SUBSCRIBE_CHOICES = ( ) INITIAL_EMAIL_SUBSCRIBE_OPTION = Setting('INITIAL_EMAIL_SUBSCRIBE_OPTION', 'y', EMAIL_SET, dict( -label = _("Default email subscription "), +label = _("Default email subscription"), widget=RadioSelect, choices=EMAIL_SUBSCRIBE_CHOICES, help_text = _("Choose what should be the default email subscription status while registering."), diff --git a/forum/settings/voting.py b/forum/settings/voting.py index 7c43ea3..aea9153 100644 --- a/forum/settings/voting.py +++ b/forum/settings/voting.py @@ -3,6 +3,10 @@ from django.utils.translation import ugettext_lazy as _ VOTE_RULES_SET = SettingSet('voting', _('Voting rules'), _("Configure the voting rules on your site."), 400) +USER_REPUTATION_TO_MAX_VOTES = Setting('USER_REPUTATION_TO_MAX_VOTES', True, VOTE_RULES_SET, dict( +label = _("Add reputation to max votes per day"), required=False, +help_text = _("The user reputation is added to the static MAX_VOTES_PER_DAY option. Users with higher reputation can vote more."))) + MAX_VOTES_PER_DAY = Setting('MAX_VOTES_PER_DAY', 30, VOTE_RULES_SET, dict( label = _("Maximum votes per day"), help_text = _("The maximum number of votes an user can cast per day."))) diff --git a/forum/views/commands.py b/forum/views/commands.py index 191cae0..af6ad64 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -73,7 +73,7 @@ def vote_post(request, id, vote_type): user_vote_count_today = user.get_vote_count_today() - if user_vote_count_today >= int(settings.MAX_VOTES_PER_DAY): + if user_vote_count_today >= user.can_vote_count_today(): raise NotEnoughLeftException(_('votes'), str(settings.MAX_VOTES_PER_DAY)) new_vote_cls = (vote_type == 'up') and VoteUpAction or VoteDownAction -- 2.39.5