[damned-lies] Also support reduced po files for all po download



commit d8ef688fe8f5c5a055d762fe42dabb632da1cd3f
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Mar 19 10:18:09 2011 +0100

    Also support reduced po files for all po download

 languages/urls.py                         |    2 +-
 languages/views.py                        |    1 +
 stats/models.py                           |   14 ++++++++------
 stats/utils.py                            |    2 +-
 templates/languages/language_release.html |    2 +-
 5 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/languages/urls.py b/languages/urls.py
index 3f9ceb2..e6726aa 100644
--- a/languages/urls.py
+++ b/languages/urls.py
@@ -21,7 +21,7 @@ urlpatterns = patterns('',
         regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+).xml$',
         view = 'languages.views.language_release_xml'),
     url(
-        regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|doc)+).tar.gz$',
+        regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|ui-part|doc)+).tar.gz$',
         view = 'languages.views.language_release_tar'),
     url(
         regex = r'^(?P<team_slug>[\w\- ]+)/$',
diff --git a/languages/views.py b/languages/views.py
index 24aaab8..2bc8c40 100644
--- a/languages/views.py
+++ b/languages/views.py
@@ -87,6 +87,7 @@ def language_release(request, locale, release_name, dtype):
             'ui-part': _("UI Translations (reduced)"),
             'doc': _("Documentation")}.get(dtype),
         'stats': stats,
+        'dtype': dtype,
         'scope': dtype.endswith('-part') and 'part' or 'full',
         'dateformat': formats.get_format('DATE_FORMAT'),
     }
diff --git a/stats/models.py b/stats/models.py
index fea55d3..2593ce1 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1110,19 +1110,21 @@ class Release(models.Model):
     def get_lang_files(self, lang, dtype):
         """ Return a list of all po files of a lang for this release, preceded by the more recent modification date
             It uses the POT file if there is no po for a module """
+        partial = False
+        if dtype == "ui-part":
+            dtype, partial = "ui", True
         pot_stats = Statistics.objects.filter(language=None, branch__releases=self, domain__dtype=dtype)
-        po_stats = Statistics.objects.filter(language=lang, branch__releases=self, domain__dtype=dtype)
+        po_stats = dict([("%s-%s" % (st.branch_id, st.domain_id), st)
+                         for st in Statistics.objects.filter(language=lang, branch__releases=self, domain__dtype=dtype)])
         lang_files = []
         last_modif_date = datetime(1970, 01, 01)
         # Create list of files
         for stat in pot_stats:
             if stat.full_po.updated > last_modif_date:
                 last_modif_date = stat.full_po.updated
-            try:
-                lang_stat = po_stats.get(branch = stat.branch, domain = stat.domain)
-            except Statistics.DoesNotExist:
-                lang_stat = stat
-            file_path = lang_stat.po_path()
+            key = "%s-%s" % (stat.branch_id, stat.domain_id)
+            lang_stat = po_stats.get(key, stat)
+            file_path = lang_stat.po_path(reduced=partial)
             if os.access(file_path, os.R_OK):
                 lang_files.append(file_path)
         return last_modif_date, lang_files
diff --git a/stats/utils.py b/stats/utils.py
index 79f0e57..9a79e37 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -101,7 +101,7 @@ def po_grep(in_file, out_file, filter_):
         filter_loc, filter_str = "locations", "gschema.xml.in"
     else:
         try:
-            filter_loc, filter_str = filter_.strip("|")
+            filter_loc, filter_str = filter_.split("|")
         except:
             # Probably bad filter syntax in DB (TODO: log it)
             return
diff --git a/templates/languages/language_release.html b/templates/languages/language_release.html
index 2f64805..db4fed4 100644
--- a/templates/languages/language_release.html
+++ b/templates/languages/language_release.html
@@ -40,7 +40,7 @@ $(document).ready(function()
 
 {% if language %}
 <hr />
-<p><a href="{% url languages.views.language_release_tar locale=language.locale release_name=release.name dtype=stats.dtype %}"><img src="{{ MEDIA_URL }}img/download.png" /> {% trans "Download all po files" %}</a></p>
+<p><a href="{% url languages.views.language_release_tar locale=language.locale release_name=release.name dtype=dtype %}"><img src="{{ MEDIA_URL }}img/download.png" /> {% trans "Download all po files" %}</a></p>
 {% endif %}
 
 </div>



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