From f955487b51f1b787a52ad3df15b286447a1dec45 Mon Sep 17 00:00:00 2001 From: hernani Date: Fri, 8 Oct 2010 01:13:51 +0000 Subject: [PATCH] Handle big reputation numbers slightly better. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@603 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- .../default/templates/question_list/item.html | 2 +- .../templates/question_summary_list_roll.html | 2 +- .../default/templates/users/signature.html | 4 ++-- forum/templatetags/extra_filters.py | 17 +++++++++++------ forum/templatetags/extra_tags.py | 6 +++++- forum_modules/exporter/forms.py | 2 +- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/forum/skins/default/templates/question_list/item.html b/forum/skins/default/templates/question_list/item.html index 19cbb36..b28cdf4 100644 --- a/forum/skins/default/templates/question_list/item.html +++ b/forum/skins/default/templates/question_list/item.html @@ -15,7 +15,7 @@
{% ifequal question.answer_count 1 %}{% trans "answer" %}{% else %}{% trans "answers" %}{% endifequal %}
-
{{question.view_count|cnprog_intword|safe}}
+
{{question.view_count|decorated_int|safe}}
{% ifequal question.view_count 1 %}{% trans "view" %}{% else %}{% trans "views" %}{% endifequal %}
diff --git a/forum/skins/default/templates/question_summary_list_roll.html b/forum/skins/default/templates/question_summary_list_roll.html index 769aa20..f80cef7 100644 --- a/forum/skins/default/templates/question_summary_list_roll.html +++ b/forum/skins/default/templates/question_summary_list_roll.html @@ -7,7 +7,7 @@ {{ question.answer_count|intcomma }} {{ question.score|intcomma }} - {{ question.view_count|cnprog_intword|safe }} + {{ question.view_count|decorated_int|safe }} {% trans "answers" %} diff --git a/forum/skins/default/templates/users/signature.html b/forum/skins/default/templates/users/signature.html index 9805429..e8aebf3 100644 --- a/forum/skins/default/templates/users/signature.html +++ b/forum/skins/default/templates/users/signature.html @@ -1,11 +1,11 @@ -{% load i18n %}{% spaceless %} +{% load i18n extra_filters %}{% spaceless %} {% if not user.is_suspended %} {% ifequal format "full" %} {% else %} {{ user.decorated_name }} - {{ user.reputation }} + {{ user.reputation|decorated_int:"" }} {% ifequal format "badges" %} {% if user.gold %} diff --git a/forum/templatetags/extra_filters.py b/forum/templatetags/extra_filters.py index df1c24d..590f555 100644 --- a/forum/templatetags/extra_filters.py +++ b/forum/templatetags/extra_filters.py @@ -1,4 +1,5 @@ from django import template +from django.utils.safestring import mark_safe import logging register = template.Library() @@ -15,13 +16,17 @@ def can_edit_post(user, post): @register.filter -def cnprog_intword(number): +def decorated_int(number, cls="thousand"): try: - if 1000 <= number < 10000: - string = str(number)[0:1] - return "%sk" % string - else: - return number + if number > 999: + if number > 9999: + s = str(number)[:-3] + else: + s = str(number) + s = "%s.%s" % (s[0], s[1]) + + return mark_safe("%sk" % (cls, s)) + return number except: return number diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py index 5602392..3e0cf4c 100644 --- a/forum/templatetags/extra_tags.py +++ b/forum/templatetags/extra_tags.py @@ -16,6 +16,7 @@ from forum import settings from django.template.defaulttags import url as default_url from forum import skins from forum.utils import html +from extra_filters import decorated_int from django.core.urlresolvers import reverse register = template.Library() @@ -47,7 +48,9 @@ def get_score_badge(user): if user.is_suspended(): return _("(suspended)") - BADGE_TEMPLATE = '%(reputation)s' + repstr = decorated_int(user.reputation, "") + + BADGE_TEMPLATE = '%(repstr)s' if user.gold > 0 : BADGE_TEMPLATE = '%s%s' % (BADGE_TEMPLATE, '' '' @@ -66,6 +69,7 @@ def get_score_badge(user): BADGE_TEMPLATE = smart_unicode(BADGE_TEMPLATE, encoding='utf-8', strings_only=False, errors='strict') return mark_safe(BADGE_TEMPLATE % { 'reputation' : user.reputation, + 'repstr': repstr, 'gold' : user.gold, 'silver' : user.silver, 'bronze' : user.bronze, diff --git a/forum_modules/exporter/forms.py b/forum_modules/exporter/forms.py index 94ce800..5e4adec 100644 --- a/forum_modules/exporter/forms.py +++ b/forum_modules/exporter/forms.py @@ -2,5 +2,5 @@ from django import forms from django.utils.translation import ugettext as _ class ExporterForm(forms.Form): - anon_data = forms.BooleanField(label=_('Anonimyzed data'), help_text=_('Don\'t export user data and make all content anonymous'), required=False) + anon_data = forms.BooleanField(label=_('Anonymized data'), help_text=_('Don\'t export user data and make all content anonymous'), required=False) \ No newline at end of file -- 2.39.5