From 55c9938df878cfcab4f15fb94ee4452e5fd16ba6 Mon Sep 17 00:00:00 2001 From: jordan Date: Thu, 22 Sep 2011 16:13:00 +0000 Subject: [PATCH] adding functionality to freeze accept rate to 100% for specific users git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1175 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/settings/users.py | 9 ++++++++- forum/templatetags/extra_tags.py | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/forum/settings/users.py b/forum/settings/users.py index 2c2c3ac..a108ebf 100644 --- a/forum/settings/users.py +++ b/forum/settings/users.py @@ -1,4 +1,4 @@ -from forms import CommaStringListWidget +from forms import CommaStringListWidget, StringListWidget from django.forms import CheckboxSelectMultiple from django.forms.widgets import RadioSelect from base import Setting, SettingSet @@ -43,6 +43,13 @@ label = _("Show user accept rate"), help_text = _("If you check this the user accept rate will be displayed on the user posts."), required=False)) +FREEZE_ACCEPT_RATE_FOR = Setting('FREEZE_ACCEPT_RATE_FOR', +["admin",], +USERS_SET, dict( +label = _("Freeze accept rate"), +help_text = _("Freeze answers accept rate for the selected users."), +widget=StringListWidget)) + TRUNCATE_USERNAMES_LONGER_THAN = Setting('TRUNCATE_USERNAMES_LONGER_THAN', 15, USERS_SET, dict( label = _("Truncate usernames longer than"), help_text = _("The usernames that are longer than this will be truncated and ... will be appended."))) diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py index e01ff06..b8d9f5c 100644 --- a/forum/templatetags/extra_tags.py +++ b/forum/templatetags/extra_tags.py @@ -86,6 +86,13 @@ def get_accept_rate(user): if not settings.SHOW_USER_ACCEPT_RATE: return "" + # Freeze accept rate for users + freeze_accept_rate_for_users_users = settings.FREEZE_ACCEPT_RATE_FOR.value + if user.username in list(freeze_accept_rate_for_users_users): + freeze = True + else: + freeze = False + # We get the number of all user's answers. total_answers_count = Answer.objects.filter(author=user).count() @@ -110,7 +117,10 @@ def get_accept_rate(user): accept_rate_number_title = _('%s has one accepted answer') % smart_unicode(user.username) # This are the only options. Otherwise there are no accepted answers at all. else: - accept_rate_number_title = _('%s has no accepted answers') % smart_unicode(user.username) + if freeze: + accept_rate_number_title = "" + else: + accept_rate_number_title = _('%s has no accepted answers') % smart_unicode(user.username) html_output = """ %(accept_rate_label)s: @@ -118,7 +128,7 @@ def get_accept_rate(user): """ % { 'accept_rate_label' : _('accept rate'), 'accept_rate_title' : _('Rate of the user\'s accepted answers'), - 'accept_rate' : int(accept_rate), + 'accept_rate' : 100 if freeze else int(accept_rate), 'accept_rate_number_title' : u'%s' % accept_rate_number_title, } -- 2.45.1