From e091bf3e0b15e6abd222b55997a1a82c33e47cc6 Mon Sep 17 00:00:00 2001 From: jordan Date: Sun, 10 Apr 2011 16:13:24 +0000 Subject: [PATCH] OSQA-315, better Unicode support for the usernames in the Accept Rate and the Award points tools. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@959 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/templatetags/extra_tags.py | 9 ++++++--- forum/templatetags/node_tags.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py index e34e996..04b260f 100644 --- a/forum/templatetags/extra_tags.py +++ b/forum/templatetags/extra_tags.py @@ -89,12 +89,15 @@ def get_accept_rate(user): # In order to represent the accept rate in percentages we divide the number of the accepted answers to the # total answers count and make a hundred multiplication. - accept_rate = (float(accepted_answers_count) / float(total_answers_count) * 100) + try: + accept_rate = (float(accepted_answers_count) / float(total_answers_count) * 100) + except ZeroDivisionError: + accept_rate = 0 # If the user has more than one accepted answers the rate title will be in plural. if accepted_answers_count > 1: accept_rate_number_title = _('%(user)s has %(count)d accepted answers') % { - 'user' : user.username, + 'user' : user.username, 'count' : int(accepted_answers_count) } # If the user has one accepted answer we'll be using singular. @@ -102,7 +105,7 @@ def get_accept_rate(user): accept_rate_number_title = _('%s has one accepted answer') % 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') % user.username + accept_rate_number_title = _('%s has no accepted answers') % smart_unicode(user.username) html_output = """ %(accept_rate_label)s: diff --git a/forum/templatetags/node_tags.py b/forum/templatetags/node_tags.py index 6680f59..6a88355 100644 --- a/forum/templatetags/node_tags.py +++ b/forum/templatetags/node_tags.py @@ -4,6 +4,7 @@ import re from forum.models import Question, Action from django.utils.translation import ungettext, ugettext as _ from django.utils.html import strip_tags +from django.utils.encoding import smart_unicode from django.utils.safestring import mark_safe from django.core.urlresolvers import reverse from django import template @@ -93,7 +94,7 @@ def post_controls(post, user): # Users should be able to award points for an answer. Users cannot award their own answers if user != post.author and user.is_authenticated(): controls.append(post_control(_("award points"), reverse('award_points', kwargs={'user_id' : post.author.id, - 'answer_id' : post.id}), title=_("award points to %s") % post.author, + 'answer_id' : post.id}), title=_("award points to %s") % smart_unicode(post.author.username), command=True, withprompt=True)) # The other controls are visible only to authenticated users. -- 2.39.5