]> git.openstreetmap.org Git - osqa.git/commitdiff
#OSQA-315, implementing the accept rate feature that shows the rate of the accepted...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sun, 10 Apr 2011 15:21:07 +0000 (15:21 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sun, 10 Apr 2011 15:21:07 +0000 (15:21 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@958 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/skins/default/media/style/style.css
forum/skins/default/templates/node/contributors_info.html
forum/templatetags/extra_tags.py

index deab17b9d6391fddead7b5639be57d1c5bd7b5a4..652bd9fe0cf490915e12e1b4371deddde67120ac 100644 (file)
@@ -1111,7 +1111,7 @@ ins {
     color: #CC9933;
 }
 
-.score {
+.score, .accept_rate {
     color: #333333;
     font-size: 110%;
     font-weight: bold;
index 3ed461b95d51a68e31b87a8ea41f7d66164aac1a..28bf49baa4a32cecd15ebb1ddc3283c01025e42f 100644 (file)
@@ -1,4 +1,4 @@
-{% load extra_tags %}
+{% load extra_tags i18n %}
 <div class='post-update-info post-update-info-user'>
     <p style="line-height:12px;">
         {{ node_verb }}
@@ -6,7 +6,8 @@
     </p>
     {% gravatar node.author 32 %}
     <p><a {% if node.author.is_suspended %}class="suspended-user" {% endif %}href="{{ node.author.get_profile_url }}">{{ node.author.decorated_name }}</a><br/>
-    {% get_score_badge node.author %}</p>
+    {% get_score_badge node.author %}<br />
+    {% get_accept_rate node.author %}</p>
 </div>
 {% if node.last_edited %}
     <div class='post-update-info post-update-info-edited'>
index 0a3c42109233e9cbc80135fe1af14b95170b5fac..e34e996da6b25a80b2c990b7a7d0fff51f15aa12 100644 (file)
@@ -78,6 +78,43 @@ def get_score_badge(user):
     'reputationword' : _('reputation points'),
     })
 
+# Usage: {% get_accept_rate node.author %}
+@register.simple_tag
+def get_accept_rate(user):
+    # We get the number of all user's answers.
+    total_answers_count = Answer.objects.filter(author=user).count()
+
+    # We get the number of the user's accepted answers.
+    accepted_answers_count = Answer.objects.filter(author=user, state_string__contains="(accepted)").count()
+
+    # 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)
+
+    # 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,
+            'count' : int(accepted_answers_count)
+        }
+    # If the user has one accepted answer we'll be using singular.
+    elif accepted_answers_count == 1:
+        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
+
+    html_output = """
+    <span title="%(accept_rate_title)s" class="accept_rate">%(accept_rate_label)s:</span>
+    <span title="%(accept_rate_number_title)s">%(accept_rate)d&#37;</span>
+    """ % {
+        'accept_rate_label' : _('accept rate'),
+        'accept_rate_title' : _('Rate of the user\'s accepted answers'),
+        'accept_rate' : int(accept_rate),
+        'accept_rate_number_title' : u'%s' % accept_rate_number_title,
+    }
+
+    return mark_safe(html_output)
 
 @register.simple_tag
 def get_age(birthday):