damned-lies r1524 - in trunk: . people stats templates



Author: claudep
Date: Sat Apr  4 07:56:21 2009
New Revision: 1524
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1524&view=rev

Log:
2009-04-04  Claude Paroz  <claude 2xlibre net>

	* people/models.py: get_languages allows to get all languages from all
	teams the user is subscribed to.
	* stats/models.py: Pass a list of languages to stat generation so as they
	are always present.
	* stats/views.py: Generate and cache branch stats in the view.
	* templates/module_detail.html: branches is now a context variable.
	* templates/stats_show.html: stat1 renamed to clearer pot_stat.
	The authenticated user's language(s) are now always shown on the module
	detail page, even when no po file have been committed.
	Fixes bug #577700.

Modified:
   trunk/ChangeLog
   trunk/people/models.py
   trunk/stats/models.py
   trunk/stats/views.py
   trunk/templates/module_detail.html
   trunk/templates/stats_show.html

Modified: trunk/people/models.py
==============================================================================
--- trunk/people/models.py	(original)
+++ trunk/people/models.py	Sat Apr  4 07:56:21 2009
@@ -118,5 +118,12 @@
         except:
             return False
 
+    def get_languages(self):
+        all_teams = [role.team for role in self.role_set.select_related('team')]
+        all_languages = []
+        for team in all_teams:
+            all_languages.extend(team.get_languages())
+        return all_languages
+
     # Related names
     # - module: maintains_modules

Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py	(original)
+++ trunk/stats/models.py	Sat Apr  4 07:56:21 2009
@@ -155,6 +155,8 @@
     def __init__(self, *args, **kwargs):
         models.Model.__init__(self, *args, **kwargs)
         self.checkout_lock = threading.Lock()
+        self._ui_stats = None
+        self._doc_stats = None
 
     def __unicode__(self):
         return "%s (%s)" % (self.name, self.module)
@@ -226,15 +228,28 @@
             os.makedirs(dirname)
         return dirname
     
-    def get_stats(self, typ):
-        """ Get statistics list of type typ ('ui' or 'doc'), in a dict of lists, key is domain.name (POT in 1st position)"""
-        stats = {}
+    def get_stats(self, typ, mandatory_langs=[]):
+        """ Get statistics list of type typ ('ui' or 'doc'), in a dict of lists, key is domain.name (POT in 1st position)
+            stats = {'po':      [potstat, polang1, polang2, ...],
+                     'po-tips': [potstat, polang1, polang2, ...]}
+            mandatory_langs is a list of language objects whose stats should be added even if no translation exists.
+        """
+        stats = {}; stats_langs = {}
         pot_stats = Statistics.objects.select_related("language", "domain", "branch").filter(branch=self, language__isnull=True, domain__dtype=typ)
         for stat in pot_stats.all():
             stats[stat.domain.name] = [stat,]
+            stats_langs[stat.domain.name] = []
         tr_stats = Statistics.objects.select_related("language", "domain", "branch").filter(branch=self, language__isnull=False, domain__dtype=typ)
         for stat in tr_stats.all():
             stats[stat.domain.name].append(stat)
+            stats_langs[stat.domain.name].append(stat.language)
+        # Check if all mandatory languages are present
+        for lang in mandatory_langs:
+            for domain in stats.keys():
+                if lang not in stats_langs[domain]:
+                    fake_stat = FakeStatistics(self.module, typ, lang)
+                    fake_stat.untranslated = stats[domain][0].untranslated
+                    stats[domain].append(fake_stat)
         # Sort
         for key, doms in stats.items():
             doms.sort(self.compare_stats)
@@ -252,11 +267,15 @@
                 res = cmp(a.get_lang(), b.get_lang())
         return res  
     
-    def get_doc_stats(self):
-        return self.get_stats('doc')
-
-    def get_ui_stats(self):
-        return self.get_stats('ui')
+    def get_doc_stats(self, mandatory_langs=[]):
+        if not self._doc_stats:
+            self._doc_stats = self.get_stats('doc', mandatory_langs)
+        return self._doc_stats
+
+    def get_ui_stats(self, mandatory_langs=[]):
+        if not self._ui_stats:
+            self._ui_stats = self.get_stats('ui', mandatory_langs)
+        return self._ui_stats
     
     def update_stats(self, force):
         """ Update statistics for all po files from the branch """
@@ -1210,9 +1229,10 @@
 class FakeStatistics(object):
     """ This is a fake statistics class where a summary value is needed for a multi-domain module
         This is used in get_lang_stats for the language-release-stats template """
-    def __init__(self, module, dtype):
+    def __init__(self, module, dtype, lang=None):
         self.module = module
         self.dtype = dtype
+        self.language = lang
         self.translated = 0
         self.fuzzy = 0
         self.untranslated = 0
@@ -1226,7 +1246,19 @@
     
     def is_fake(self):
         return True
-        
+
+    def get_lang(self):
+        if self.language:
+            return _("%(lang_name)s (%(lang_locale)s)") % { 
+                'lang_name': _(self.language.name),
+                'lang_locale': self.language.locale
+            }
+        else:
+            return "pot file"
+
+    def get_translationstat(self):
+        return "%d%%&nbsp;(%d/%d/%d)" % (self.tr_percentage(), self.translated, self.fuzzy, self.untranslated)
+
     def pot_size(self):
         return int(self.translated) + int(self.fuzzy) + int(self.untranslated)
     def tr_percentage(self):
@@ -1248,7 +1280,8 @@
         return self.module.name
     def module_description(self):
         return self.module.description
-       
+    def most_important_message(self):
+        return None
 
 class ArchivedStatistics(models.Model):
     module = models.TextField()

Modified: trunk/stats/views.py
==============================================================================
--- trunk/stats/views.py	(original)
+++ trunk/stats/views.py	Sat Apr  4 07:56:21 2009
@@ -43,9 +43,18 @@
 
 def module(request, module_name):
     mod = get_object_or_404(Module, name=module_name)
+    branches = mod.get_branches()
+    if request.user.is_authenticated():
+        person = request.user.person
+        langs = person.get_languages()
+        for branch in branches:
+            branch.get_ui_stats(mandatory_langs=langs)
+            branch.get_doc_stats(mandatory_langs=langs)
+    
     context = {
         'pageSection':  "module",
         'module': mod,
+        'branches': branches,
         'non_standard_repo_msg' : _(settings.VCS_HOME_WARNING),
         'can_edit_branches': mod.can_edit_branches(request.user),
     }

Modified: trunk/templates/module_detail.html
==============================================================================
--- trunk/templates/module_detail.html	(original)
+++ trunk/templates/module_detail.html	Sat Apr  4 07:56:21 2009
@@ -46,10 +46,10 @@
   </tr>
 </table>
 
-{% if module.branch_set.all %}
+{% if branches %}
   <!-- Links to branches of module -->
   <p><strong>{% trans "Branches:" %}</strong>
-  {% for branch in module.get_branches %}
+  {% for branch in branches %}
     {% ifnotequal forloop.counter 1 %} - {% endifnotequal %}
     <a href="#{{ branch.name }}">{{ branch.name }}</a>
   {% endfor %}
@@ -59,7 +59,7 @@
   </p>
 
   <!-- Main loop through branches -->
-  {% for branch in module.get_branches %}
+  {% for branch in branches %}
     <h2><a name="{{ branch.name }}"></a>{{ branch.name }}
     {% if branch.get_vcs_web_url %}
       <small>(<a href="{{ branch.get_vcs_web_url }}">{% trans "Browse Repository" %}</a>)</small>

Modified: trunk/templates/stats_show.html
==============================================================================
--- trunk/templates/stats_show.html	(original)
+++ trunk/templates/stats_show.html	Sat Apr  4 07:56:21 2009
@@ -1,22 +1,22 @@
 {% load i18n %}
 
 {% for dname, stat in stats.items %}
-  {% with stat|first as stat1 %} 
-  <h3>{% trans stat1.domain.get_description %}
-  {% ifnotequal stat1.domain.directory 'help' %}
-    {% ifnotequal stat1.domain.directory 'po' %}
+  {% with stat|first as pot_stat %} 
+  <h3>{% trans pot_stat.domain.get_description %}
+  {% ifnotequal pot_stat.domain.directory 'help' %}
+    {% ifnotequal pot_stat.domain.directory 'po' %}
     <br />
-    <span class="path">{{ stat1.domain.directory }}</span>
+    <span class="path">{{ pot_stat.domain.directory }}</span>
     {% endifnotequal %}
   {% endifnotequal %}
   </h3>
-  <a href="{{ stat1.po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download POT file" %}" /></a>
-  {{ stat1.pot_text }}
+  <a href="{{ pot_stat.po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download POT file" %}" /></a>
+  {{ pot_stat.pot_text }}
   <!-- This is the title of the section that lists notices about a module -->
-  {% if stat1.information_set.all %}
+  {% if pot_stat.information_set.all %}
   <h4>{% trans "Notices" %}</h4>
   <table>
-    {% for msg in stat1.information_set.all %}
+    {% for msg in pot_stat.information_set.all %}
     <tr>
       <td valign="top"><img src="{{ msg.get_icon }}" alt="{{ msg.type }}" /></td>
       <td>{{ msg.get_description|safe }}</td>
@@ -28,7 +28,7 @@
   <table class="stats">
     <thead><tr>
         <th>{% trans "Language" %}</th><th>{% trans "Translated" %}</th>
-        {% if stat1.fig_count %}
+        {% if pot_stat.fig_count %}
         <th></th>
         {% endif %}
         <th>{% trans "Graph" %}</th>
@@ -37,7 +37,7 @@
     {% for line in stat %}
     {% if not forloop.first %}
     <tr>
-      <td class="leftcell"><a href="{% url vertimus-names-view module.name branch.name stat1.domain.name line.language.locale %}">{{ line.get_lang }}</a>
+      <td class="leftcell"><a href="{% url vertimus-names-view module.name branch.name pot_stat.domain.name line.language.locale %}">{{ line.get_lang }}</a>
         {% with line.most_important_message as msg %} 
         {% if msg %}
         <img src="{{ msg.get_icon }}" title="{{ msg.get_description }}" alt="{{ msg.type }}" />
@@ -45,8 +45,8 @@
         {% endwith %}
       </td>
       <td>{{ line.get_translationstat|safe }}</td>
-      {% if stat1.fig_count %}
-      <td><a href="{% url stats.views.docimages module_name=module.name,potbase=stat1.domain.name,branch_name=branch.name,langcode=line.language.locale %}">
+      {% if pot_stat.fig_count %}
+      <td><a href="{% url stats.views.docimages module_name=module.name,potbase=pot_stat.domain.name,branch_name=branch.name,langcode=line.language.locale %}">
           <img src="{{ MEDIA_URL }}img/figure.png" alt="{% trans "Display document figures" %}"></a>
       </td>
       {% endif %}



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