[damned-lies] Display categories in same order than defined in code
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Display categories in same order than defined in code
- Date: Sat, 15 Dec 2012 18:46:10 +0000 (UTC)
commit 7fb0efc28a0e20b937e318d0272bfc3632e950b7
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Dec 15 19:44:13 2012 +0100
Display categories in same order than defined in code
Fixes bug #686077. Thanks Gil Forcada for the report and initial
patch.
stats/models.py | 48 +++++++++++++++++++++++-------------------------
1 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 61c086c..e00dd30 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1210,12 +1210,6 @@ class Category(models.Model):
def __unicode__(self):
return "%s (%s, %s)" % (self.get_name_display(), self.release, self.branch)
- @classmethod
- def get_cat_name(cls, key):
- for entry in CATEGORY_CHOICES:
- if key == entry[0]:
- return _(entry[1])
- return key
class PoFile(models.Model):
# File type fields of Django may not be flexible enough for our use case
@@ -1644,7 +1638,7 @@ class Statistics(models.Model):
stats = {'dtype':dtype, 'totaltrans':0, 'totalfuzzy':0, 'totaluntrans':0,
'totaltransperc': 0, 'totalfuzzyperc': 0, 'totaluntransperc': 0,
- 'categs':{}, 'all_errors':[]}
+ 'categs': SortedDict(), 'all_errors': []}
# Sorted by module to allow grouping ('fake' stats)
pot_stats = Statistics.objects.select_related('domain', 'branch__module', 'full_po', 'part_po')
if release:
@@ -1676,16 +1670,20 @@ class Statistics(models.Model):
if vt_state.id in actions_dict:
vt_state.last_comment = actions_dict[vt_state.id].comment
+ category_choices_dict = dict(CATEGORY_CHOICES)
for stat in pot_stats:
- categdescr = "default"
+ categ_key = "default"
if release:
- categdescr = stat.categ_name
+ categ_key = '%d-%s' % (category_choices_dict.keys().index(stat.categ_name), stat.categ_name)
domname = stat.domain.description and _(stat.domain.description) or ""
branchname = stat.branch.name
modname = stat.branch.module.name
- if categdescr not in stats['categs']:
- stats['categs'][categdescr] = {'cattrans':0, 'catfuzzy':0, 'catuntrans':0,
- 'cattransperc':0, 'modules':{}}
+ if categ_key not in stats['categs']:
+ stats['categs'][categ_key] = {
+ 'cattrans': 0, 'catfuzzy': 0, 'catuntrans': 0, 'cattransperc': 0,
+ 'catname': _(category_choices_dict[stat.categ_name]),
+ 'modules': {}
+ }
# Try to get translated stat, else stick with POT stat
br_dom_key = "%d-%d" % (stat.branch.id, stat.domain.id)
if br_dom_key in tr_stats_dict:
@@ -1702,23 +1700,23 @@ class Statistics(models.Model):
stats['totaltrans'] += stat.translated(scope)
stats['totalfuzzy'] += stat.fuzzy(scope)
stats['totaluntrans'] += stat.untranslated(scope)
- stats['categs'][categdescr]['cattrans'] += stat.translated(scope)
- stats['categs'][categdescr]['catfuzzy'] += stat.fuzzy(scope)
- stats['categs'][categdescr]['catuntrans'] += stat.untranslated(scope)
- if modname not in stats['categs'][categdescr]['modules']:
+ stats['categs'][categ_key]['cattrans'] += stat.translated(scope)
+ stats['categs'][categ_key]['catfuzzy'] += stat.fuzzy(scope)
+ stats['categs'][categ_key]['catuntrans'] += stat.untranslated(scope)
+ if modname not in stats['categs'][categ_key]['modules']:
# first element is a placeholder for a fake stat
- stats['categs'][categdescr]['modules'][modname] = {branchname:[[' fake', None], (domname, stat)]}
- elif branchname not in stats['categs'][categdescr]['modules'][modname]:
+ stats['categs'][categ_key]['modules'][modname] = {branchname:[[' fake', None], (domname, stat)]}
+ elif branchname not in stats['categs'][categ_key]['modules'][modname]:
# first element is a placeholder for a fake stat
- stats['categs'][categdescr]['modules'][modname][branchname] = [[' fake', None], (domname, stat)]
+ stats['categs'][categ_key]['modules'][modname][branchname] = [[' fake', None], (domname, stat)]
else:
# Here we add the 2nd or more stat to the same module-branch
- if len(stats['categs'][categdescr]['modules'][modname][branchname]) == 2:
+ if len(stats['categs'][categ_key]['modules'][modname][branchname]) == 2:
# Create a fake statistics object for module summary
- stats['categs'][categdescr]['modules'][modname][branchname][0][1] = FakeSummaryStatistics(stat.domain.module, stat.branch, dtype)
- stats['categs'][categdescr]['modules'][modname][branchname][0][1].trans(stats['categs'][categdescr]['modules'][modname][branchname][1][1])
- stats['categs'][categdescr]['modules'][modname][branchname].append((domname, stat))
- stats['categs'][categdescr]['modules'][modname][branchname][0][1].trans(stat)
+ stats['categs'][categ_key]['modules'][modname][branchname][0][1] = FakeSummaryStatistics(stat.domain.module, stat.branch, dtype)
+ stats['categs'][categ_key]['modules'][modname][branchname][0][1].trans(stats['categs'][categ_key]['modules'][modname][branchname][1][1])
+ stats['categs'][categ_key]['modules'][modname][branchname].append((domname, stat))
+ stats['categs'][categ_key]['modules'][modname][branchname][0][1].trans(stat)
# Compute percentages and sorting
stats['total'] = stats['totaltrans'] + stats['totalfuzzy'] + stats['totaluntrans']
@@ -1726,8 +1724,8 @@ class Statistics(models.Model):
stats['totaltransperc'] = int(100*stats['totaltrans']/stats['total'])
stats['totalfuzzyperc'] = int(100*stats['totalfuzzy']/stats['total'])
stats['totaluntransperc'] = int(100*stats['totaluntrans']/stats['total'])
+ stats['categs'].keyOrder.sort()
for key, categ in stats['categs'].items():
- categ['catname'] = Category.get_cat_name(key)
categ['cattotal'] = categ['cattrans'] + categ['catfuzzy'] + categ['catuntrans']
if categ['cattotal'] > 0:
categ['cattransperc'] = int(100*categ['cattrans']/categ['cattotal'])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]