]> git.openstreetmap.org Git - osqa.git/commitdiff
Resolves Jira OSQA-359, adding an option to allow negative user reputation in the...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 17 May 2011 12:21:16 +0000 (12:21 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 17 May 2011 12:21:16 +0000 (12:21 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1042 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/action.py
forum/models/user.py
forum/settings/users.py

index 58ec7d55f145b90331128d86f66909c2f9ffebf9..3692d7bc85f96ab2144033234674f6ba5e42bf81 100644 (file)
@@ -300,7 +300,7 @@ class ActionRepute(models.Model):
         return 0
 
     def _add_to_rep(self, value):
-        if self.user.reputation + value < 1:
+        if (self.user.reputation + value < 1) and not settings.ALLOW_NEGATIVE_REPUTATION:
             return 0
         else:
             return models.F('reputation') + value
index ae8f9387d2d4fe82d492595eb98722ad9f2f9c63..f00f3783fe0a4748ed92c1f2310786e0906c71df 100644 (file)
@@ -113,7 +113,7 @@ class User(BaseModel, DjangoUser):
     is_approved = models.BooleanField(default=False)
     email_isvalid = models.BooleanField(default=False)
 
-    reputation = models.PositiveIntegerField(default=0)
+    reputation = models.IntegerField(default=0)
     gold = models.PositiveIntegerField(default=0)
     silver = models.PositiveIntegerField(default=0)
     bronze = models.PositiveIntegerField(default=0)
@@ -176,7 +176,8 @@ class User(BaseModel, DjangoUser):
         return md5(self.email.lower()).hexdigest()
     
     def save(self, *args, **kwargs):
-        if self.reputation < 0:
+        # If the community doesn't allow negative reputation, set it to 0
+        if not settings.ALLOW_NEGATIVE_REPUTATION and self.reputation < 0:
             self.reputation = 0
 
         new = not bool(self.id)
index 3d7a9f324888c24475dab5038317a09b1a757f17..7bc58eccad87a93162953716264f213a472a8af8 100644 (file)
@@ -6,6 +6,11 @@ from django.utils.translation import ugettext as _
 
 USERS_SET = SettingSet('users', _('Users settings'), _("General settings for the OSQA users."), 20)
 
+ALLOW_NEGATIVE_REPUTATION = Setting('ALLOW_NEGATIVE_REPUTATION', True, USERS_SET, dict(
+label = _("Allow negative reputation"),
+help_text = _("Check if you want to allow negative user reputations in the community."),
+required=False))
+
 STORE_GREETING_IN_COOKIE = Setting('STORE_GREETING_IN_COOKIE', True, USERS_SET, dict(
 label = _("Store greeting in cookie"),
 help_text = _("If you check this the greeting will be stored in a cookie and the users won't be notified on logout."),