[damned-lies] Clean module_image and reuse num_stats template tag



commit a62c3d52ab4dbbdbfc3d4a98e8b52f8954d9e832
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu May 19 21:10:57 2011 +0200

    Clean module_image and reuse num_stats template tag

 stats/templatetags/stats_extras.py |   16 +++++++++++-----
 stats/views.py                     |    8 +++++---
 templates/module_images.html       |    8 ++------
 3 files changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index f916b33..0b65422 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -2,7 +2,7 @@ from django import template
 from django.utils.safestring import mark_safe
 from django.utils.translation import get_language_bidi
 
-from stats.models import PoFile
+from stats.models import PoFile, Statistics, FakeStatistics
 
 register = template.Library()
 
@@ -38,10 +38,16 @@ def browse_bugs(module, content):
 @register.filter
 def num_stats(stat, scope='full'):
     """ Produce stat numbers as in: 85% (1265/162/85) """
-    return mark_safe("%s%%&nbsp;(%s/%s/%s)" % (
-        stat.tr_percentage(scope), stat.translated(scope),
-        stat.fuzzy(scope), stat.untranslated(scope))
-    )
+    if isinstance(stat, (Statistics, FakeStatistics)):
+        stats = {
+            'prc':          stat.tr_percentage(scope),
+            'translated':   stat.translated(scope),
+            'fuzzy':        stat.fuzzy(scope),
+            'untranslated': stat.untranslated(scope),
+        }
+    else:
+        stats = stat
+    return mark_safe("%(prc)s%%&nbsp;(%(translated)s/%(fuzzy)s/%(untranslated)s)" % stats)
 
 @register.filter
 def vis_stats(stat, scope='full'):
diff --git a/stats/views.py b/stats/views.py
index 7b48dab..b12d9d2 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -156,9 +156,11 @@ def docimages(request, module_name, potbase, branch_name, langcode):
         branch = get_object_or_404(Branch, module__pk=mod.id, name=branch_name)
         stat   = FakeStatistics(mod, branch, 'doc', lang)
     context = {
-        'pageSection':  "module",
-        'module': mod,
-        'stat': stat
+        'pageSection': "module",
+        'module':   mod,
+        'stat':     stat,
+        'locale':   stat.language.locale,
+        'figstats': stat.fig_stats(),
     }
     return render(request, 'module_images.html', context)
 
diff --git a/templates/module_images.html b/templates/module_images.html
index 547ad5c..c559edb 100644
--- a/templates/module_images.html
+++ b/templates/module_images.html
@@ -1,5 +1,5 @@
 {% extends "base.html" %}
-{% load i18n %}
+{% load i18n stats_extras %}
 
 {% block title %} {% blocktrans with module.description as name %}Module Doc Figure Status: {{ name }}{% endblocktrans %} {% endblock %}
 
@@ -8,15 +8,12 @@
 
 <h1><a href="{% url stats.views.module module.name %}">{{ module.description }}</a> {% trans stat.domain.description %} ({% trans stat.language.name %})</h1>
 
-{% with stat.fig_stats as figstat %}
 <h2>{% trans "Figures translation status" %} &mdash; 
-    <small>{{ figstat.prc }}% ({{ figstat.translated }}/{{ figstat.fuzzy}}/{{ figstat.untranslated }})</small></h2>
-{% endwith %}
+    <small>{{ figstats|num_stats }}</small></h2>
 
 <table class="stats">
 <thead><tr><th width="50%">{% trans "Original" %}</th><th width="50%">{% trans stat.language.name %}</th></tr></thead>
 {% for fig in stat.get_figures %}
-  {% with stat.language.locale as locale %}
   <tr><td valign="top">
     <a href="{{ fig.orig_remote_url }}"><span class="path">C/{{ fig.path }}</span><br/></a>
     {% if fig.video %}<video src="{{ fig.orig_remote_url }}" controls></video>
@@ -51,7 +48,6 @@
     {% endif %}
     </td>
   </tr>
-  {% endwith %}
 {% endfor %}
 </table>
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]