damned-lies r1206 - in trunk: . stats templates templates/languages



Author: stephaner
Date: Sun Dec  7 22:57:38 2008
New Revision: 1206
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1206&view=rev

Log:
2008-12-07  StÃphane Raimbault  <stephane raimbault gmail com>

	* stats/models.py: Remove a loop with a better SQL query in
	Module.get_head_branch(). More simple is_head function (looks for
	SVN/trunk too). Module.compare_branches is now a __cmp__ method of
	Branch. Faster Branch.has_string_frozen(). Use a simple list() in
	get_branches to avoid the list comprehension.  New
	BRANCH_HEAD_NAMES tuple to respect the DRY principle. Remove a
	list comprehension on dict.items() whereas dict.values returns the
	same result. PEP-8 on Information, ArchivedInformation and
	ArchivedStatistics.
	* templates/module_detail.html: Replaced 'i' by 'em' and 'b' by 'strong'
	Fix missing </a>. HTML indent.
	* templates/languages/language_release_stats.html
	* templates/stats_show.html: PEP-8 on Information.


Modified:
   trunk/ChangeLog
   trunk/stats/models.py
   trunk/templates/languages/language_release_stats.html
   trunk/templates/module_detail.html
   trunk/templates/stats_show.html

Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py	(original)
+++ trunk/stats/models.py	Sun Dec  7 22:57:38 2008
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (c) 2008 Claude Paroz <claude 2xlibre net>.
+# Copyright (c) 2008 Stephane Raimbault <stephane raimbault gmail com>.
 #
 # This file is part of Damned Lies.
 #
@@ -40,6 +41,12 @@
     ('bzr', 'Bazaar')
 )
 
+BRANCH_HEAD_NAMES = (
+    'HEAD',
+    'trunk',
+    'master'
+)
+
 class Module(models.Model):
     name = models.CharField(max_length=50)
     homepage = models.URLField(null=True, blank=True)
@@ -82,33 +89,27 @@
         if self.bugs_base.find("bugzilla") != -1 or self.bugs_base.find("freedesktop") != -1:
             return "%senter_bug.cgi?product=%s&amp;component=%s" % (self.bugs_base, self.bugs_product, self.bugs_component)
         else:
-            return self.bugs_base
-    
-    def compare_branches(self, a, b):
-        if a.name in ('HEAD', 'master'):
-            return -1
-        elif b.name in ('HEAD', 'master'):
-            return 1
-        else:
-            return cmp(a.name, b.name)*-1    
+            return self.bugs_base 
     
     def get_branches(self):
-        branches = [b for b in self.branch_set.all()]
-        branches.sort(self.compare_branches)
+        branches = list(self.branch_set.all())
+        branches.sort()
         return branches
     
     def get_head_branch(self):
         """ Returns the HEAD (trunk, master, ...) branch of the module """
-        for branch in self.branch_set.all():
-            if branch.name in ('HEAD', 'trunk', 'master'):
-                return branch
-        return None
+        branch = self.branch_set.filter(name__in = BRANCH_HEAD_NAMES)
+        if branch:
+            # First one (if many something is wrong :-/)
+            return branch[0]
+        else:
+            return None
     
     def can_edit_branches(self, user):
         """ Returns True for superusers, users with adequate permissions or maintainers of the module """ 
         if user.is_superuser or \
            user.has_perms(['stats.delete_branch', 'stats.add_branch', 'stats.change_branch']) or \
-           user.username in [p.username for p in self.maintainers.all()]:
+           user.username in [ p.username for p in self.maintainers.all() ]:
             return True
         return False
 
@@ -142,19 +143,20 @@
         upd_thread = threading.Thread(target=self.update_stats, kwargs={'force':True})
         upd_thread.start()
 
+    def __cmp__(self, other):
+        if self.name in BRANCH_HEAD_NAMES:
+            return -1
+        elif other.name in BRANCH_HEAD_NAMES:
+            return 1
+        else:
+            return -cmp(self.name, other.name)
+
     def is_head(self):
-        if self.module.vcs_type in ('cvs', 'svn') and self.name == "HEAD":
-            return True
-        elif self.module.vcs_type == 'git' and self.name == "master":
-            return True
-        return False
+        return self.name in BRANCH_HEAD_NAMES
 
     def has_string_frozen(self):
         """ Returns true if the branch is contained in at least one string frozen release """
-        for rel in self.releases.all():
-            if rel.string_frozen:
-                return True
-        return False
+        return self.releases.filter(string_frozen=True).count() and True or False
            
     def get_vcs_url(self):
         if self.module.vcs_type in ('hg', 'git'):
@@ -677,7 +679,8 @@
                     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 = stats.values()
         results.sort(self.compare_stats)
         return results 
     
@@ -1033,15 +1036,15 @@
        
 
 class ArchivedStatistics(models.Model):
-    Module = models.TextField(db_column='module')
-    Type = models.CharField(db_column='type', max_length=3, choices=DOMAIN_TYPE_CHOICES)
-    Domain = models.TextField(db_column='domain')
-    Branch = models.TextField(db_column='branch')
-    Language = models.CharField(db_column='language', max_length=15)
-    Date = models.DateTimeField(db_column='date')
-    Translated = models.IntegerField(db_column='translated', default=0)
-    Fuzzy = models.IntegerField(db_column='fuzzy', default=0)
-    Untranslated = models.IntegerField(db_column='untranslated', default=0)
+    module = models.TextField()
+    type = models.CharField(max_length=3, choices=DOMAIN_TYPE_CHOICES)
+    domain = models.TextField()
+    branch = models.TextField()
+    language = models.CharField(max_length=15)
+    date = models.DateTimeField()
+    translated = models.IntegerField(default=0)
+    fuzzy = models.IntegerField(default=0)
+    untranslated = models.IntegerField(default=0)
 
     class Meta:
         db_table = 'archived_statistics'
@@ -1052,23 +1055,22 @@
     ('error','Error')
 )
 class Information(models.Model):
-    Statistics = models.ForeignKey('Statistics', db_column='statistics_id')
+    statistics = models.ForeignKey('Statistics')
     # Priority of a stats message
-    Type = models.CharField(db_column='type', max_length=5,
-                            choices=INFORMATION_TYPE_CHOICES)
-    Description = models.TextField(db_column='description')
+    type = models.CharField(max_length=5, choices=INFORMATION_TYPE_CHOICES)
+    description = models.TextField()
 
     class Meta:
         db_table = 'information'
 
     def __cmp__(self, other):
-        return cmp(self.Statistics.module_name(), other.Statistics.module_name())
+        return cmp(self.statistics.module_name(), other.statistics.module_name())
 
     def get_icon(self):
-        return "/media/img/%s.png" % self.Type
+        return "/media/img/%s.png" % self.type
     
     def get_description(self):
-        text = self.Description
+        text = self.description
         matches = re.findall('###([^#]*)###',text) 
         if matches:
             text = re.sub('###([^#]*)###', '%s', text)
@@ -1081,11 +1083,10 @@
         return text
 
 class ArchivedInformation(models.Model):
-    Statistics = models.ForeignKey('ArchivedStatistics', db_column='statistics_id')
+    statistics = models.ForeignKey('ArchivedStatistics')
     # Priority of a stats message
-    Type = models.CharField(db_column='type', max_length=5, 
-                            choices=INFORMATION_TYPE_CHOICES)
-    Description = models.TextField(db_column='description')
+    type = models.CharField(max_length=5, choices=INFORMATION_TYPE_CHOICES)
+    description = models.TextField()
 
     class Meta:
         db_table = 'archived_information'

Modified: trunk/templates/languages/language_release_stats.html
==============================================================================
--- trunk/templates/languages/language_release_stats.html	(original)
+++ trunk/templates/languages/language_release_stats.html	Sun Dec  7 22:57:38 2008
@@ -52,7 +52,7 @@
             {% endif %}
             {{ dom.1.module_description }}</a>
             {% for err in dom.1.information_set.all %}
-              <img src="{{ err.get_icon }}" title="{{ err.get_description }}" alt="{{ err.Type }}" />
+              <img src="{{ err.get_icon }}" title="{{ err.get_description }}" alt="{{ err.type }}" />
             {% endfor %}
             </td>
           {% endif %}
@@ -78,7 +78,7 @@
   <h3>{% trans "Error summary" %}</h3>
   <ul>
   {% for err in modstats.all_errors %}
-    <li><img src="{{ err.get_icon }}" alt="{{ err.Type }}" /> {{ err.Statistics.module_name }}:<br />
+    <li><img src="{{ err.get_icon }}" alt="{{ err.type }}" /> {{ err.statistics.module_name }}:<br />
         <span class="error">{{ err.get_description }}</span></li>
   {% endfor %}
   </ul>

Modified: trunk/templates/module_detail.html
==============================================================================
--- trunk/templates/module_detail.html	(original)
+++ trunk/templates/module_detail.html	Sun Dec  7 22:57:38 2008
@@ -1,7 +1,10 @@
 {% extends "base.html" %}
 {% load i18n %}
 
-{% block title %} {% blocktrans with module.get_description as name %}Module Statistics: {{ name }}{% endblocktrans %} {% endblock %}
+{% block title %}
+{% blocktrans with module.get_description as name %}Module Statistics: {{ name }}
+{% endblocktrans %}
+{% endblock %}
 
 {% block content %}
 <div class="mainpage">
@@ -12,7 +15,7 @@
   <p>{{ module.comment|safe }}</p>
 {% else %}
   {% ifnotequal module.vcs_root "http://svn.gnome.org/svn"; %}
-  <p><i><img src="/media/img/warn.png" alt="Warning logo" />{% trans "This module is not part of the GNOME SVN repository. Please check the module's web page to see where to send translations." %}</i></p>
+  <p><em><img src="/media/img/warn.png" alt="Warning logo" />{% trans "This module is not part of the GNOME SVN repository. Please check the module's web page to see where to send translations." %}</em></p>
   {% endifnotequal %}
 {% endif %}
 
@@ -20,38 +23,37 @@
   <p><a href="{{ module.homepage }}">{{ module.homepage }}</a></p>
 {% endif %}
 
-<table><tr><td width="50%" valign="top">
-
-{% if module.maintainers.all %}
-  <h2>{% trans "Maintainers" %}</h2>
-  {% for person in module.maintainers.all %}
-    {% with 0 as printroles %}
-    {% include "person_base.html" %}
-    {% endwith %}
-  {% endfor %}
-{% endif %}
-
-</td><td width="50%" valign="top">
-
-{% if module.bugs_base %}
-  <h2>{% trans "Bug reporting" %}</h2>
-  <ul>
-  {% if module.get_bugs_i18n_url %}
-    <li><a href="{{ module.get_bugs_i18n_url }}">{% trans "Show existing i18n and l10n bugs" %}</li>
-  {% endif %}
-  <li><a href="{{ module.get_bugs_enter_url }}">{% trans "Report bugs to Bugzilla" %}</a></li>
-  </ul>
-{% endif %}
-
-</td></tr></table>
+<table>
+  <tr>
+    <td width="50%" valign="top">
+      {% if module.maintainers.all %}
+      <h2>{% trans "Maintainers" %}</h2>
+      {% for person in module.maintainers.all %}
+        {% with 0 as printroles %}
+        {% include "person_base.html" %}
+        {% endwith %}
+      {% endfor %}
+      {% endif %}
+    </td>
+    <td width="50%" valign="top">
+      {% if module.bugs_base %}
+      <h2>{% trans "Bug reporting" %}</h2>
+      <ul>
+        {% if module.get_bugs_i18n_url %}
+        <li><a href="{{ module.get_bugs_i18n_url }}">{% trans "Show existing i18n and l10n bugs" %}</a></li>
+        {% endif %}
+        <li><a href="{{ module.get_bugs_enter_url }}">{% trans "Report bugs to Bugzilla" %}</a></li>
+      </ul>
+      {% endif %}
+    </td>
+  </tr>
+</table>
 
 {% if module.branch_set.all %}
   <!-- Links to branches of module -->
-  <p><b>{% trans "Branches:" %}</b>
+  <p><strong>{% trans "Branches:" %}</strong>
   {% for branch in module.get_branches %}
-    {% ifnotequal forloop.counter 1 %} 
-    - 
-    {% endifnotequal %}
+    {% ifnotequal forloop.counter 1 %} - {% endifnotequal %}
     <a href="#{{ branch.name }}">{{ branch.name }}</a>
   {% endfor %}
   {% if can_edit_branches %}

Modified: trunk/templates/stats_show.html
==============================================================================
--- trunk/templates/stats_show.html	(original)
+++ trunk/templates/stats_show.html	Sun Dec  7 22:57:38 2008
@@ -16,7 +16,7 @@
     <h4>{% trans "Notices" %}</h4>
     <table>
     {% for msg in stat1.information_set.all %}
-      <tr><td valign="top"><img src="{{ msg.get_icon }}" alt="{{ msg.Type }}" /></td><td>{{ msg.get_description|safe }}</td></tr>
+      <tr><td valign="top"><img src="{{ msg.get_icon }}" alt="{{ msg.type }}" /></td><td>{{ msg.get_description|safe }}</td></tr>
     {% endfor %}
     </table>
   {% endif %}
@@ -34,7 +34,7 @@
       <td class="leftcell"><a href="{{ line.po_url }}">{{ 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 }}" />
+      <img src="{{ msg.get_icon }}" title="{{ msg.get_description }}" alt="{{ msg.type }}" />
       {% endif %}
       {% endwith %}
       </td>



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