damned-lies r1491 - in trunk: . media/css stats stats/templatetags templates templates/registration vertimus



Author: claudep
Date: Fri Mar 13 22:12:51 2009
New Revision: 1491
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1491&view=rev

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

	* README: Add note about SCRATCHDIR.
	* media/css/main.css: Add translation coverage classes.
	* stats/templatetags/stats_extras.py: New filter to produce css class for
	translation coverage.
	* stats/models.py: New total_by_releases method to compute multi-release
	stats.
	* stats/views.py:
	* templates/release_compare.html:
	* urls.py: Add view, template and url for release comparison.
	* templates/registration/password_reset_complete.html: Fix login link.
	* vertimus/views.py: Set max column width in diff view (translator
	comments are not wrapped).

Added:
   trunk/templates/release_compare.html
Modified:
   trunk/ChangeLog
   trunk/README
   trunk/media/css/main.css
   trunk/stats/models.py
   trunk/stats/templatetags/stats_extras.py
   trunk/stats/views.py
   trunk/templates/registration/password_reset_complete.html
   trunk/urls.py
   trunk/vertimus/views.py

Modified: trunk/README
==============================================================================
--- trunk/README	(original)
+++ trunk/README	Fri Mar 13 22:12:51 2009
@@ -45,6 +45,8 @@
 1 - Rename settings_sample.py to settings.py and review settings
     (please refer to Database configuration below for more
     informations).
+    SCRATCHDIR should point to an existing directory, writable by
+    the web application user.
 
 2 - Run 'python manage.py syncdb'
 

Modified: trunk/media/css/main.css
==============================================================================
--- trunk/media/css/main.css	(original)
+++ trunk/media/css/main.css	Fri Mar 13 22:12:51 2009
@@ -22,13 +22,25 @@
   text-align: left;
 }
 
+td.supported {
+  color: #FFFFFF;
+  background-color: green; 
+}
+td.partially {
+  background-color: orange;
+}
+td.not_supported {
+}
+
 /* styles related to jQuery tablesorter component */
 table.tablesorter thead tr .header {
   background-image: url(../img/bg.gif);
   background-repeat: no-repeat;
   background-position: center right;
   background-color: #EEEEEE;
+  border-bottom: #AAAAAA solid 1px;
   cursor: pointer;
+  padding-right: 1em;
 }
 
 table.tablesorter thead tr .headerSortUp {

Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py	(original)
+++ trunk/stats/models.py	Fri Mar 13 22:12:51 2009
@@ -643,7 +643,53 @@
 
     def __unicode__(self):
         return self.description
-    
+
+    @classmethod
+    def total_by_releases(cls, dtype, releases):
+        """ Get summary stats for all languages and 'releases', and return a 'stats' dict with
+            each language locale as the key:
+            stats{
+              'll': (<language name>, percentage for release 1, percentage for release 2, ...),
+              'll': ...
+            }
+        """
+        rel_ids = [str(rel.id) for rel in releases]
+        LOCALE, NAME, REL_ID, TRANS, FUZZY, UNTRANS = 0, 1, 2, 3, 4, 5
+        query = """
+            SELECT language.locale, language.name, category.release_id,
+                   SUM(stat.translated), 
+                   SUM(stat.fuzzy),
+                   SUM(stat.untranslated)
+            FROM statistics AS stat
+            LEFT JOIN language
+                   ON stat.language_id = language.id
+            INNER JOIN domain 
+                   ON stat.domain_id = domain.id
+            INNER JOIN branch 
+                   ON stat.branch_id = branch.id
+            INNER JOIN category 
+                   ON category.branch_id = branch.id 
+            WHERE domain.dtype = %%s
+              AND category.release_id IN (%s)
+            GROUP BY language_id, category.release_id
+            ORDER BY language.name""" % (",".join(rel_ids),)
+        cursor = connection.cursor()
+        cursor.execute(query, (dtype,))
+        stats = {}; totals = [0] * len(releases)
+        for row in cursor.fetchall():
+            if row[LOCALE] not in stats:
+                stats[row[LOCALE]] = [0] * len(releases)
+                stats[row[LOCALE]].insert(0, _(row[NAME])) # translated language name
+            if row[LOCALE] == None: # POT stats
+                totals[rel_ids.index(str(row[REL_ID]))] = row[UNTRANS]
+            else:
+                stats[row[LOCALE]][rel_ids.index(str(row[REL_ID]))+1] = row[TRANS]
+        # Compute percentages
+        def perc(x, y): return int(x/y * 100)
+        for k in stats.keys():
+            stats[k] = [stats[k][0]] + map(perc, stats[k][1:], totals)
+        return stats
+
     def total_strings(self):
         """ Returns the total number of strings in the release as a tuple (doc_total, ui_total) """
         # Uses the special statistics record where language_id is NULL to compute the sum.

Modified: trunk/stats/templatetags/stats_extras.py
==============================================================================
--- trunk/stats/templatetags/stats_extras.py	(original)
+++ trunk/stats/templatetags/stats_extras.py	Fri Mar 13 22:12:51 2009
@@ -2,9 +2,18 @@
 
 register = template.Library()
 
+ register filter
 def linked_with(value, arg):
     """ This filter returns an object (passed in value) enclosed with his absolute url 
         arg is the linked text """
     return "<a href='%s'>%s</a>" % (value.get_absolute_url(), arg)
 
-register.filter(linked_with)
+ register filter
+def support_class(value):
+    """ Returns a class depending on the coverage of the translation stats.
+        Value is a translation percentage """
+    if value >= 80:
+        return "supported"
+    elif value >= 50:
+        return "partially"
+    return "not_supported"

Modified: trunk/stats/views.py
==============================================================================
--- trunk/stats/views.py	(original)
+++ trunk/stats/views.py	Fri Mar 13 22:12:51 2009
@@ -150,3 +150,14 @@
         }
         return render_to_response('release_detail.html', context, context_instance=RequestContext(request))
 
+def compare_by_releases(request, dtype, rels_to_compare):
+    releases = []
+    for rel_id in rels_to_compare.split("-"):
+        # Important to keep the ordering of the url
+        releases.append(Release.objects.get(id=rel_id))
+    stats = Release.total_by_releases(dtype, releases)
+    context = {
+        'releases': releases,
+        'stats': stats
+    }
+    return render_to_response('release_compare.html', context, context_instance=RequestContext(request))

Modified: trunk/templates/registration/password_reset_complete.html
==============================================================================
--- trunk/templates/registration/password_reset_complete.html	(original)
+++ trunk/templates/registration/password_reset_complete.html	Fri Mar 13 22:12:51 2009
@@ -9,6 +9,6 @@
 
 <p>{% trans "Your password has been set. You may go ahead and log in now." %}</p>
 
-<p><a href="{{ login_url }}">{% trans 'Log in' %}</a></p>
+<p><a href="{% url login %}">{% trans 'Log in' %}</a></p>
 </div>
 {% endblock %}

Added: trunk/templates/release_compare.html
==============================================================================
--- (empty file)
+++ trunk/templates/release_compare.html	Fri Mar 13 22:12:51 2009
@@ -0,0 +1,49 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% load stats_extras %}
+
+{% block title %} {% trans "Releases Comparison" %} {% endblock %}
+{% block extrahead %}
+<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.min.js"></script> 
+<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.tablesorter.min.js"></script>
+<script type="text/javascript">
+$(document).ready(function() 
+    { 
+        $("#stats").tablesorter(); 
+    }
+);
+</script>
+{% endblock %}
+
+{% block content %}
+<div class="mainpage">
+
+<h1>{% trans "Releases Comparison" %}</h1>
+
+<table class="tablesorter" id="stats">
+  <thead>
+    <tr>
+    <th class="header">{% trans "Languages" %}</th>
+    {% for rel in releases %}
+      <th class="header">{{ rel.name }}</th>
+    {% endfor %}
+    </tr>
+  </thead>
+
+{% for locale, stat in stats.items %}
+<tr class="stats">
+  {% for perc in stat %}
+    {% if forloop.first %}
+      <td class="stats leftcell">
+        {{ perc }} ({{ locale }})
+      </td>
+    {% else %}
+      <td class="stats {{ perc|support_class }}">{{ perc }}%</td>
+    {% endif %}
+  {% endfor %}
+</tr>
+{% endfor %}
+</table>
+
+</div>
+{% endblock %}

Modified: trunk/urls.py
==============================================================================
--- trunk/urls.py	(original)
+++ trunk/urls.py	Fri Mar 13 22:12:51 2009
@@ -32,6 +32,7 @@
     (r'^module/(?P<module_name>[\w\-\+]+)/(?P<potbase>[\w-]+)/(?P<branch_name>[\w-]+)/(?P<langcode>[\w ]+)/images/$', 'docimages'),
     url(r'^releases/(?P<format>(html|json|xml))?/?$', 'releases', name='releases'),
     (r'^releases/(?P<release_name>[\w-]+)/(?P<format>(html|xml))?/?$', 'release'),
+    (r'^releases/compare/(?P<dtype>\w+)/(?P<rels_to_compare>[\w-]+)/$', 'compare_by_releases'),
 )
 
 if 'django_openid' in settings.INSTALLED_APPS:

Modified: trunk/vertimus/views.py
==============================================================================
--- trunk/vertimus/views.py	(original)
+++ trunk/vertimus/views.py	Fri Mar 13 22:12:51 2009
@@ -148,7 +148,7 @@
             file_path_2 = stats.po_path()
 
     content_2 = [l.decode('utf-8') for l in open(file_path_2, 'U').readlines()]
-    d = difflib.HtmlDiff()
+    d = difflib.HtmlDiff(wrapcolumn=80)
     diff_content = d.make_table(content_2, content_1,
                                 descr_2, descr_1, context=True)
 



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