From 786505648a5cb20e335a51a1e69555a868c33332 Mon Sep 17 00:00:00 2001 From: jordan Date: Tue, 17 May 2011 12:21:16 +0000 Subject: [PATCH] Resolves Jira OSQA-359, adding an option to allow negative user reputation in the community. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1042 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/action.py | 2 +- forum/models/user.py | 5 +++-- forum/settings/users.py | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/forum/models/action.py b/forum/models/action.py index 58ec7d5..3692d7b 100644 --- a/forum/models/action.py +++ b/forum/models/action.py @@ -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 diff --git a/forum/models/user.py b/forum/models/user.py index ae8f938..f00f378 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -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) diff --git a/forum/settings/users.py b/forum/settings/users.py index 3d7a9f3..7bc58ec 100644 --- a/forum/settings/users.py +++ b/forum/settings/users.py @@ -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."), -- 2.45.1