# 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.
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 = """
<span title="%(accept_rate_title)s" class="accept_rate">%(accept_rate_label)s:</span>
from forum.models import Question, Action\r
from django.utils.translation import ungettext, ugettext as _\r
from django.utils.html import strip_tags\r
+from django.utils.encoding import smart_unicode\r
from django.utils.safestring import mark_safe\r
from django.core.urlresolvers import reverse\r
from django import template\r
# Users should be able to award points for an answer. Users cannot award their own answers\r
if user != post.author and user.is_authenticated():\r
controls.append(post_control(_("award points"), reverse('award_points', kwargs={'user_id' : post.author.id,\r
- 'answer_id' : post.id}), title=_("award points to %s") % post.author,\r
+ 'answer_id' : post.id}), title=_("award points to %s") % smart_unicode(post.author.username),\r
command=True, withprompt=True))\r
\r
# The other controls are visible only to authenticated users.\r