[damned-lies] Preserve the '0's in stats on some pages



commit 191c1205aef70166d641f3742b3720cc257fdf8c
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Mar 3 17:53:34 2014 +0100

    Preserve the '0's in stats on some pages
    
    Fixes bug #721247. Thanks Andika Triwidada for the report and
    Danilo Rodrigo for the initial patch.

 stats/templatetags/stats_extras.py      |   13 +++++++++++--
 templates/vertimus/vertimus_detail.html |    8 ++++----
 vertimus/tests/tests.py                 |    2 ++
 3 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index cfdfa49..1082bdc 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -92,7 +92,15 @@ def num_word_stats(stat, scope='full'):
 
 
 def num_stats_helper(stat, scope='full', strings=True):
-    """ Produce stat numbers as in: 85% (1265/162/85) """
+    """
+    Produce stat numbers as in: 85% (1265/162/85)
+    0s are hidden unless scope ends with ',zeros'
+    """
+    if ',' in scope:
+        scope, zeros = scope.split(',', 1)
+        show_zeros = zeros == 'zeros'
+    else:
+        show_zeros = False
     if isinstance(stat, (Statistics,
                          FakeLangStatistics,
                          FakeSummaryStatistics)):
@@ -134,7 +142,8 @@ def num_stats_helper(stat, scope='full', strings=True):
         stats['prc'] = stats['translated_perc']
     if 'prc' in stats:
         result = STATISTICS % stats
-        result = result.replace(' 0</span>', ' &nbsp;</span>')
+        if not show_zeros:
+            result = result.replace(' 0</span>', ' &nbsp;</span>')
     else:
         result = "%(translated)s/%(fuzzy)s/%(untranslated)s" % stats
     return mark_safe(result)
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index fb57be2..0b3c137 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -77,11 +77,11 @@ $(document).ready(function() {
     {% trans "PO file statistics:" %} <br />
        <div id="stats_po">
     <div title="{% trans "Translated/Fuzzy/Untranslated" %}">
-               <span>{% trans "Strings:" %} {{ stats|num_stats:"full" }}</span>&nbsp;
+               <span>{% trans "Strings:" %} {{ stats|num_stats:"full,zeros" }}</span>&nbsp;
        <div class="graph graphinline">
         {{ stats|vis_stats:"full" }}
        </div>
-               <span style="margin-left: 15px;">{% trans "Words:" %} {{ stats|num_word_stats:"full" 
}}</span>&nbsp;
+               <span style="margin-left: 15px;">{% trans "Words:" %} {{ stats|num_word_stats:"full,zeros" 
}}</span>&nbsp;
        <div class="graph graphinline">
         {{ stats|vis_word_stats:"full" }}
        </div>
@@ -109,11 +109,11 @@ $(document).ready(function() {
     <br />
        <div id="stats_po">
     <div title="{% trans "Translated/Fuzzy/Untranslated" %}">
-               <span>{% trans "Strings:" %} {{ stats|num_stats:"part" }}</span>&nbsp;
+               <span>{% trans "Strings:" %} {{ stats|num_stats:"part,zeros" }}</span>&nbsp;
       <div class="graph graphinline">
         {{ stats|vis_stats:"full" }}
       </div>
-               <span style="margin-left: 15px;">{% trans "Words:" %} {{ stats|num_word_stats:"part" 
}}</span>&nbsp;
+               <span style="margin-left: 15px;">{% trans "Words:" %} {{ stats|num_word_stats:"part,zeros" 
}}</span>&nbsp;
       <div class="graph graphinline">
         {{ stats|vis_word_stats:"full" }}
       </div>
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index fd1220b..a6d0b3f 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -439,6 +439,8 @@ class VertimusTest(TeamsAndRolesTests):
         url = reverse('vertimus_by_ids', args=[self.b.id, self.d.id, self.l.id])
         response = self.client.get(url)
         self.assertNotContains(response, '<option value="WC">')
+        self.assertContains(response,
+            '<span class="num1">      0</span><span class="num2">     0</span><span class="num3">     
0</span>')
 
         self.client.login(username=self.pn.username, password='password')
         response = self.client.get(url)


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