[damned-lies] Share code between num_stats and num_word_stats
- From: Gil Forcada Codinachs <gforcada src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Share code between num_stats and num_word_stats
- Date: Sun, 21 Apr 2013 15:04:51 +0000 (UTC)
commit 8271e3d6f5bacda570492b76c3b4c5b301252b36
Author: Gil Forcada <gforcada gnome org>
Date: Sun Apr 21 17:03:57 2013 +0200
Share code between num_stats and num_word_stats
stats/templatetags/stats_extras.py | 77 +++++++++++++++++---------------------
1 file changed, 35 insertions(+), 42 deletions(-)
---
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index bdceeb3..eae110f 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -82,58 +82,51 @@ def browse_bugs(module, content):
@register.filter
def num_stats(stat, scope='full'):
- """ Produce stat numbers as in: 85% (1265/162/85) """
- if isinstance(stat, (Statistics,
- FakeLangStatistics,
- FakeSummaryStatistics)):
- stats = {
- 'prc': stat.tr_percentage(scope),
- 'translated': stat.translated(scope),
- 'fuzzy': stat.fuzzy(scope),
- 'untranslated': stat.untranslated(scope),
- }
- elif isinstance(stat, PoFile):
- stats = {
- 'translated': stat.translated,
- 'fuzzy': stat.fuzzy,
- 'untranslated': stat.untranslated,
- }
- if scope != 'short':
- stats['prc'] = stat.tr_percentage()
- else:
- stats = stat
- if 'translated_perc' in stats:
- stats['prc'] = stats['translated_perc']
-
- if 'prc' in stats:
- result = STATISTICS % stats
- result = result.replace(' 0</span>', ' </span>')
- else:
- result = "%(translated)s/%(fuzzy)s/%(untranslated)s" % stats
-
- return mark_safe(result)
+ return num_stats_helper(stat, scope=scope, strings=True)
@register.filter
def num_word_stats(stat, scope='full'):
+ return num_stats_helper(stat, scope=scope, strings=False)
+
+
+def num_stats_helper(stat, scope='full', strings=True):
""" Produce stat numbers as in: 85% (1265/162/85) """
if isinstance(stat, (Statistics,
FakeLangStatistics,
FakeSummaryStatistics)):
- stats = {
- 'prc': stat.tr_word_percentage(scope),
- 'translated': stat.translated_words(scope),
- 'fuzzy': stat.fuzzy_words(scope),
- 'untranslated': stat.untranslated_words(scope),
- }
+ if strings:
+ stats = {
+ 'prc': stat.tr_percentage(scope),
+ 'translated': stat.translated(scope),
+ 'fuzzy': stat.fuzzy(scope),
+ 'untranslated': stat.untranslated(scope),
+ }
+ else:
+ stats = {
+ 'prc': stat.tr_word_percentage(scope),
+ 'translated': stat.translated_words(scope),
+ 'fuzzy': stat.fuzzy_words(scope),
+ 'untranslated': stat.untranslated_words(scope),
+ }
elif isinstance(stat, PoFile):
- stats = {
- 'translated': stat.translated_words,
- 'fuzzy': stat.fuzzy_words,
- 'untranslated': stat.untranslated_words,
- }
+ if strings:
+ stats = {
+ 'translated': stat.translated,
+ 'fuzzy': stat.fuzzy,
+ 'untranslated': stat.untranslated,
+ }
+ else:
+ stats = {
+ 'translated': stat.translated_words,
+ 'fuzzy': stat.fuzzy_words,
+ 'untranslated': stat.untranslated_words,
+ }
if scope != 'short':
- stats['prc'] = stat.tr_word_percentage()
+ if strings:
+ stats['prc'] = stat.tr_percentage()
+ else:
+ stats['prc'] = stat.tr_word_percentage()
else:
stats = stat
if 'translated_perc' in stats:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]