[damned-lies: 5/9] Add a release-by-language view with reduced ui po files (ui-part)
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies: 5/9] Add a release-by-language view with reduced ui po files (ui-part)
- Date: Wed, 16 Mar 2011 09:05:08 +0000 (UTC)
commit 15307feafe9e45c381c01ef3c67794bd28abe387
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Mar 4 19:51:45 2011 +0100
Add a release-by-language view with reduced ui po files (ui-part)
languages/urls.py | 2 +-
languages/views.py | 7 ++-
stats/models.py | 77 +++++++++++++--------
stats/templatetags/stats_extras.py | 9 +++
templates/languages/language_release_stats.html | 3 +-
templates/languages/language_release_summary.html | 2 +-
6 files changed, 64 insertions(+), 36 deletions(-)
---
diff --git a/languages/urls.py b/languages/urls.py
index ea5f971..3f9ceb2 100644
--- a/languages/urls.py
+++ b/languages/urls.py
@@ -14,7 +14,7 @@ urlpatterns = patterns('',
view = 'languages.views.release_archives',
name = 'language_release_archives'),
url(
- regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|doc)+)/$',
+ regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|ui-part|doc)+)/$',
view = 'languages.views.language_release',
name = 'language_release'),
url(
diff --git a/languages/views.py b/languages/views.py
index 1fea639..eebcecc 100644
--- a/languages/views.py
+++ b/languages/views.py
@@ -81,9 +81,12 @@ def language_release(request, locale, release_name, dtype):
'language': language,
'language_name': language and language.get_name() or _("Original strings"),
'release': release,
- 'stats_title': {'ui': _("UI Translations"),
- 'doc': _("Documentation")}.get(dtype),
+ 'stats_title': {
+ 'ui': _("UI Translations"),
+ 'ui-part': _("UI Translations (reduced)"),
+ 'doc': _("Documentation")}.get(dtype),
'stats': stats,
+ 'scope': dtype.endswith('-part') and 'part' or 'full',
'dateformat': formats.get_format('DATE_FORMAT'),
}
return render_to_response('languages/language_release.html', context,
diff --git a/stats/models.py b/stats/models.py
index 82677b2..14dd692 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -323,7 +323,7 @@ class Branch(models.Model):
for domain in stats.keys():
if lang not in stats_langs[domain]:
fake_stat = FakeStatistics(self.module, self, typ, lang)
- fake_stat.untranslated = stats[domain][0].untranslated
+ fake_stat.untranslated = stats[domain][0].untranslated()
stats[domain].append(fake_stat)
# Sort
for key, doms in stats.items():
@@ -337,7 +337,7 @@ class Branch(models.Model):
elif not b.language:
return 1
else:
- res = -cmp(a.translated, b.translated)
+ res = -cmp(a.translated(), b.translated())
if not res:
res = cmp(a.get_lang(), b.get_lang())
return res
@@ -1186,15 +1186,14 @@ class Statistics(models.Model):
return "%s (%s-%s) %s (%s)" % (self.branch.module.name, self.domain.dtype, self.domain.name,
self.branch.name, self.get_lang())
- @property
- def translated(self):
- return getattr(self.full_po, 'translated', 0)
- @property
- def fuzzy(self):
- return getattr(self.full_po, 'fuzzy', 0)
- @property
- def untranslated(self):
- return getattr(self.full_po, 'untranslated', 0)
+ def translated(self, scope='full'):
+ return getattr(scope=='part' and self.part_po or self.full_po, 'translated', 0)
+
+ def fuzzy(self, scope='full'):
+ return getattr(scope=='part' and self.part_po or self.full_po, 'fuzzy', 0)
+
+ def untranslated(self, scope='full'):
+ return getattr(scope=='part' and self.part_po or self.full_po, 'untranslated', 0)
def is_fake(self):
return False
@@ -1202,14 +1201,26 @@ class Statistics(models.Model):
def is_pot_stats(self):
return self.language is None
- def tr_percentage(self):
- return self.full_po and self.full_po.tr_percentage() or 0
-
- def fu_percentage(self):
- return self.full_po and self.full_po.fu_percentage() or 0
-
- def un_percentage(self):
- return self.full_po and self.full_po.un_percentage() or 0
+ def tr_percentage(self, scope='full'):
+ if scope == 'full' and self.full_po:
+ return self.full_po.tr_percentage()
+ elif scope == 'part' and self.part_po:
+ return self.part_po.tr_percentage()
+ return 0
+
+ def fu_percentage(self, scope='full'):
+ if scope == 'full' and self.full_po:
+ return self.full_po.fu_percentage()
+ elif scope == 'part' and self.part_po:
+ return self.part_po.fu_percentage()
+ return 0
+
+ def un_percentage(self, scope='full'):
+ if scope == 'full' and self.full_po:
+ return self.full_po.un_percentage()
+ elif scope == 'part' and self.part_po:
+ return self.part_po.un_percentage()
+ return 0
def get_lang(self):
if not self.is_pot_stats():
@@ -1416,17 +1427,23 @@ class Statistics(models.Model):
"""
from vertimus.models import StateDb, ActionDb # import here to prevent a circular dependency
+ if dtype.endswith('-part'):
+ dtype = dtype[:-5]
+ scope = "part"
+ else:
+ scope = "full"
+
stats = {'dtype':dtype, 'totaltrans':0, 'totalfuzzy':0, 'totaluntrans':0,
'totaltransperc': 0, 'totalfuzzyperc': 0, 'totaluntransperc': 0,
'categs':{}, 'all_errors':[]}
# Sorted by module to allow grouping ('fake' stats)
- pot_stats = Statistics.objects.select_related('domain', 'branch__module', 'full_po')
+ pot_stats = Statistics.objects.select_related('domain', 'branch__module', 'full_po', 'part_po')
if release:
pot_stats = pot_stats.extra(select={'categ_name': "category.name"}).filter(language=None, branch__releases=release, domain__dtype=dtype).order_by('branch__module__id')
else:
pot_stats = pot_stats.filter(language=None, domain__dtype=dtype).order_by('branch__module__id')
- tr_stats = Statistics.objects.select_related('domain', 'language', 'branch__module', 'full_po')
+ tr_stats = Statistics.objects.select_related('domain', 'language', 'branch__module', 'full_po', 'part_po')
if release:
tr_stats = tr_stats.filter(language=lang, branch__releases=release, domain__dtype=dtype).order_by('branch__module__id')
else:
@@ -1473,12 +1490,12 @@ class Statistics(models.Model):
if br_dom_key in vt_states_dict:
stat.state = vt_states_dict[br_dom_key]
- stats['totaltrans'] += stat.translated
- stats['totalfuzzy'] += stat.fuzzy
- stats['totaluntrans'] += stat.untranslated
- stats['categs'][categdescr]['cattrans'] += stat.translated
- stats['categs'][categdescr]['catfuzzy'] += stat.fuzzy
- stats['categs'][categdescr]['catuntrans'] += stat.untranslated
+ 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']:
# first element is a placeholder for a fake stat
stats['categs'][categdescr]['modules'][modname] = {branchname:[[' fake', None], (domname, stat)]}
@@ -1532,9 +1549,9 @@ class FakeStatistics(object):
self.figures = None
def trans(self, stat):
- self.translated += stat.translated
- self.fuzzy += stat.fuzzy
- self.untranslated += stat.untranslated
+ self.translated += stat.translated()
+ self.fuzzy += stat.fuzzy()
+ self.untranslated += stat.untranslated()
stat.partial_po = True
def is_fake(self):
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index b8e55c6..ab496bc 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -1,4 +1,5 @@
from django import template
+from django.utils.safestring import mark_safe
register = template.Library()
@@ -26,3 +27,11 @@ def escapeat(value):
@register.filter
def domain_type(stat):
return stat.domain.get_type(stat.branch)
+
+ register filter
+def num_stats(stat, scope):
+ """ Produce stat numbers as in: 85% (1265/162/85) """
+ return mark_safe("%s%% (%s/%s/%s)" % (
+ stat.tr_percentage(scope), stat.translated(scope),
+ stat.fuzzy(scope), stat.untranslated(scope))
+ )
diff --git a/templates/languages/language_release_stats.html b/templates/languages/language_release_stats.html
index 6fc13e8..4c762cf 100644
--- a/templates/languages/language_release_stats.html
+++ b/templates/languages/language_release_stats.html
@@ -66,8 +66,7 @@
{% endif %}
</td>
<td><span class="branch">{{ branch }}</span></td>
- <td><span style="display:none;">{{ stat.tr_percentage }}</span>
- {{ stat.tr_percentage }}% ({{ stat.translated }}/{{ stat.fuzzy }}/{{ stat.untranslated }})</td>
+ <td><span style="display:none;">{{ stat.tr_percentage }}</span>{{ stat|num_stats:scope }}</td>
<td style="width: 108px; text-align: center;"><div class="graph">
<div class="translated" style="width: {{ stat.tr_percentage }}px;"></div>
<div class="fuzzy" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ stat.tr_percentage }}px; width:{{ stat.fu_percentage }}px;"></div>
diff --git a/templates/languages/language_release_summary.html b/templates/languages/language_release_summary.html
index be8fde1..00bb8ea 100644
--- a/templates/languages/language_release_summary.html
+++ b/templates/languages/language_release_summary.html
@@ -32,7 +32,7 @@ Following variables should be set:
{% endwith %}
</div>
</td>
- <td class="stats_numb"><a href="{% url language_release lang.locale,stat.name,"ui" %}">
+ <td class="stats_numb"><a href="{% url language_release lang.locale,stat.name,"ui-part" %}">
{{ stat.uitransperc_part }}% ({{ stat.uitrans_part }}/{{ stat.uifuzzy_part }}/{{ stat.uiuntrans_part }})</a>
</td>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]