damned-lies r1110 - in branches/djamnedlies: . stats stats/conf templates



Author: claudep
Date: Mon Oct 27 10:18:10 2008
New Revision: 1110
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1110&view=rev

Log:
2008-10-27  Claude Paroz  <claude 2xlibre net>

	* stats/conf/settings_sample.py: Herit DATABASE_ENGINE setting.
	* stats/models.py: Add Language methods to normalize/denormalize 
	langcode in URLs (URL resolver doesn't support @ char).
	Requote release table, but with ANSI quotes, and set adequate mode
	when DB backend is MySQL.
	Prevent divide by 0 in get_global_stats.
	* stats/views.py: Handle case where langcode is "slug" normalized.
	* templates/person_base.html: maintains and translates are now methods
	from Person object.
	* templates/release.html: url tag needs {%

Modified:
   branches/djamnedlies/ChangeLog
   branches/djamnedlies/stats/conf/settings_sample.py
   branches/djamnedlies/stats/models.py
   branches/djamnedlies/stats/views.py
   branches/djamnedlies/templates/person_base.html
   branches/djamnedlies/templates/release.html

Modified: branches/djamnedlies/stats/conf/settings_sample.py
==============================================================================
--- branches/djamnedlies/stats/conf/settings_sample.py	(original)
+++ branches/djamnedlies/stats/conf/settings_sample.py	Mon Oct 27 10:18:10 2008
@@ -1,6 +1,7 @@
 from django.conf import settings
 import os
 
+DATABASE_ENGINE = getattr(settings, "DATABASE_ENGINE")
 DEBUG = getattr(settings, "DEBUG", True)
 WHEREAREWE = 'http://l10n.gnome.org/'
 WEBROOT = "/stats"

Modified: branches/djamnedlies/stats/models.py
==============================================================================
--- branches/djamnedlies/stats/models.py	(original)
+++ branches/djamnedlies/stats/models.py	Mon Oct 27 10:18:10 2008
@@ -58,6 +58,11 @@
     def get_absolute_url(self):
         return ('person_view', [str(self.id)])
 
+    def maintains(self):
+        return self.module_set.all()
+    
+    def translates(self):
+        return Team.objects.filter(coordinator=self.id)
 
 class Team(Group):
     """ The name of the team is stored in Group.name.
@@ -94,6 +99,21 @@
     def get_absolute_url(self):
         return ('language', [self.locale])
 
+    def slug_locale(self):
+        return self.locale.replace('@', '_at_')
+    
+    @classmethod
+    def slug_locale(cls, loc_string):
+        if loc_string:
+            return loc_string.replace('@', '_at_')
+        return None
+
+    @classmethod
+    def unslug_locale(cls, loc_string):
+        if loc_string:
+            return loc_string.replace('_at_', '@')
+        return None
+    
     def bugs_url_enter(self):
         return "http://bugzilla.gnome.org/enter_bug.cgi?product=l10n&amp;component=%s%%20[%s]"; %  (self.name, self.locale)
         
@@ -526,10 +546,12 @@
                       LEFT JOIN domain ON domain.id=stat.domain_id
                       LEFT JOIN branch AS br ON br.id=stat.branch_id
                       LEFT JOIN category AS cat ON br.category_id=cat.id
-                      LEFT JOIN release AS rel ON rel.id = cat.release_id 
+                      LEFT JOIN "release" AS rel ON rel.id = cat.release_id 
                       WHERE rel.id=%s AND stat.language_id IS NULL
                       GROUP BY domain.dtype """
         cursor = connection.cursor()
+        if settings.DATABASE_ENGINE == 'mysql':
+            cursor.execute("SET sql_mode='ANSI_QUOTES'")
         cursor.execute(query, (self.id,))
         totaldoc = 0; totalui = 0
         for row in cursor.fetchall():
@@ -596,7 +618,8 @@
         for row in cursor.fetchall():
             if not stats.has_key(row[1]):
                 # Initialize stats dict
-                stats[row[1]] = {'lang':row[0], 'lang_code':row[1], 'doc_trans':0, 'doc_fuzzy':0, 'doc_untrans': total_docstrings,
+                stats[row[1]] = {'lang':row[0], 'lang_code':Language.slug_locale(row[1]),
+                                  'doc_trans':0, 'doc_fuzzy':0, 'doc_untrans': total_docstrings,
                                   'doc_percent':0, 'doc_percentfuzzy':0, 'doc_percentuntrans':100,
                                   'ui_trans':0, 'ui_fuzzy':0, 'ui_untrans': total_uistrings,
                                   'ui_percent':0, 'ui_percentfuzzy':0, 'ui_percentuntrans':100}
@@ -604,16 +627,18 @@
                 stats[row[1]]['doc_trans'] = row[3]
                 stats[row[1]]['doc_fuzzy'] = row[4]
                 stats[row[1]]['doc_untrans'] = total_docstrings - (row[3] + row[4])
-                stats[row[1]]['doc_percent'] = int(100*row[3]/total_docstrings)
-                stats[row[1]]['doc_percentfuzzy'] = int(100*row[4]/total_docstrings)
-                stats[row[1]]['doc_percentuntrans'] = int(100*stats[row[1]]['doc_untrans']/total_docstrings)
+                if total_docstrings > 0:
+                    stats[row[1]]['doc_percent'] = int(100*row[3]/total_docstrings)
+                    stats[row[1]]['doc_percentfuzzy'] = int(100*row[4]/total_docstrings)
+                    stats[row[1]]['doc_percentuntrans'] = int(100*stats[row[1]]['doc_untrans']/total_docstrings)
             if row[2] == 'ui':
                 stats[row[1]]['ui_trans'] = row[3]
                 stats[row[1]]['ui_fuzzy'] = row[4]
                 stats[row[1]]['ui_untrans'] = total_uistrings - (row[3] + row[4])
-                stats[row[1]]['ui_percent'] = int(100*row[3]/total_uistrings)
-                stats[row[1]]['ui_percentfuzzy'] = int(100*row[4]/total_uistrings)
-                stats[row[1]]['ui_percentuntrans'] = int(100*stats[row[1]]['ui_untrans']/total_uistrings)
+                if total_uistrings > 0:
+                    stats[row[1]]['ui_percent'] = int(100*row[3]/total_uistrings)
+                    stats[row[1]]['ui_percentfuzzy'] = int(100*row[4]/total_uistrings)
+                    stats[row[1]]['ui_percentuntrans'] = int(100*stats[row[1]]['ui_untrans']/total_uistrings)
         cursor.close()
         results = [stat for key, stat in stats.items()]
         results.sort(self.compare_stats)
@@ -632,7 +657,7 @@
             Used for displaying the language-release template """
         
         # Sorted by module to allow grouping ('fake' stats)
-        pot_stats = Statistics.objects.filter(language=None, branch__category__release=self).order_by('domain__module__id')
+        pot_stats = Statistics.objects.filter(language=None, branch__category__release=self).order_by('domain__module__id', 'domain__dtype')
         stats = {'doc':{'totaltrans':0, 'totalfuzzy':0, 'totaluntrans':0, 'categs':{}}, 
                  'ui':{'totaltrans':0, 'totalfuzzy':0, 'totaluntrans':0, 'categs':{}} 
                 }

Modified: branches/djamnedlies/stats/views.py
==============================================================================
--- branches/djamnedlies/stats/views.py	(original)
+++ branches/djamnedlies/stats/views.py	Mon Oct 27 10:18:10 2008
@@ -133,7 +133,7 @@
 
 def languagerelease(request, langcode, release_id):
     rel = Release.objects.get(id=release_id)
-    lang = Language.objects.get(locale=langcode)
+    lang = Language.objects.get(locale=Language.unslug_locale(langcode))
     rel_stats = rel.get_lang_stats(lang)
     context = {
         'pageSection': "languages",

Modified: branches/djamnedlies/templates/person_base.html
==============================================================================
--- branches/djamnedlies/templates/person_base.html	(original)
+++ branches/djamnedlies/templates/person_base.html	Mon Oct 27 10:18:10 2008
@@ -1,5 +1,4 @@
 {# Variables $person and $printroles must be defined prior to calling this template #}
-{# If $printroles !=0 $roles must also be defined #}
 {# This template is included in person.html, team.html and language-release.html #}
 
 {% load i18n %}
@@ -37,19 +36,19 @@
   {% endif %}
 
   {% if printroles %}
-      {% if roles.maintains %}
+      {% if person.maintains %}
       <h2>{% trans "Maintains:" %}</h2>
       <ul>
-        {% for module in roles.maintains %}
+        {% for module in person.maintains %}
         <li><a href="{% url stats.views.module module.name%} ">{{ module.description }}</a></li>
         {% endfor %}
       </ul>
       {% endif %}
 
-      {% if roles.translates %}
+      {% if person.translates %}
       <h2>{% trans "Translates:" %}</h2>
       <ul>
-        {% for team in roles.translates %}
+        {% for team in person.translates %}
           {% url stats.views.team team.name as team_url %}
           <li>{% blocktrans with team.description as teamdesc %}Coordinates <a href="{{ team_url }}">{{ teamdesc }}</a>{% endblocktrans %}
         {% endfor %}

Modified: branches/djamnedlies/templates/release.html
==============================================================================
--- branches/djamnedlies/templates/release.html	(original)
+++ branches/djamnedlies/templates/release.html	Mon Oct 27 10:18:10 2008
@@ -19,7 +19,7 @@
 {% for lstats in release.get_global_stats %}
 <tr>
   <td class="leftcell" style="font-size:120%;">
-    <a href="{{ url languagerelease lstats.lang_code, release.id }}">{% trans lstats.lang %}</a>
+    <a href="{% url languagerelease langcode=lstats.lang_code release_id=release.id %}">{% trans lstats.lang %}</a>
   </td>
   
   {% ifnotequal lstats.doc_trans|add:lstats.doc_fuzzy "0" %}



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