]> git.openstreetmap.org Git - osqa.git/commitdiff
Added an option to allow users with higher reputation vote more than the users with...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 4 Jan 2011 11:43:52 +0000 (11:43 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 4 Jan 2011 11:43:52 +0000 (11:43 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@667 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/user.py
forum/settings/email.py
forum/settings/voting.py
forum/views/commands.py

index 8f2ccd015e27cef3846edc944fa0f3fe86e84708..8ef201dc01cf9dce5e59c15ac8e1d308aa55d8b6 100644 (file)
@@ -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
index 2a46e294bb101132de37f8a6034803603911dc30..4c9486a5dd7a57b46778e465362300342368a7a0 100644 (file)
@@ -11,7 +11,7 @@ EMAIL_SUBSCRIBE_CHOICES = (
 )\r
 \r
 INITIAL_EMAIL_SUBSCRIBE_OPTION = Setting('INITIAL_EMAIL_SUBSCRIBE_OPTION', 'y', EMAIL_SET, dict(\r
-label = _("Default email subscription "),\r
+label = _("Default email subscription"),\r
 widget=RadioSelect,\r
 choices=EMAIL_SUBSCRIBE_CHOICES,\r
 help_text = _("Choose what should be the default email subscription status while registering."),\r
index 7c43ea3995366d8816b56a45b77dc64c6bb58896..aea915380e98e079935b1410b18ba1965623ffda 100644 (file)
@@ -3,6 +3,10 @@ from django.utils.translation import ugettext_lazy as _
 \r
 VOTE_RULES_SET = SettingSet('voting', _('Voting rules'), _("Configure the voting rules on your site."), 400)\r
 \r
+USER_REPUTATION_TO_MAX_VOTES = Setting('USER_REPUTATION_TO_MAX_VOTES', True, VOTE_RULES_SET, dict(\r
+label = _("Add reputation to max votes per day"), required=False,\r
+help_text = _("The user reputation is added to the static MAX_VOTES_PER_DAY option. Users with higher reputation can vote more.")))\r
+\r
 MAX_VOTES_PER_DAY = Setting('MAX_VOTES_PER_DAY', 30, VOTE_RULES_SET, dict(\r
 label = _("Maximum votes per day"),\r
 help_text = _("The maximum number of votes an user can cast per day.")))\r
index 191cae01d07ab5d1b6b497e22a7e6deed63e4173..af6ad644e8ee6466dad347890b9995e15722a214 100644 (file)
@@ -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