[damned-lies] Fix download link for reduced po files when no translation exists (Fixes #656275)



commit 7760bf8db272c65199800ca00ae7c8774cd1280c
Author: Claude Paroz <claude 2xlibre net>
Date:   Wed Aug 10 17:01:10 2011 +0200

    Fix download link for reduced po files when no translation exists (Fixes #656275)

 stats/fixtures/sample_data.json |  178 ++++++++++++++++++++++-----------------
 stats/models.py                 |    6 +-
 stats/tests/__init__.py         |   29 +++++--
 stats/tests/fixture_factory.py  |    6 +-
 stats/views.py                  |    6 +-
 5 files changed, 137 insertions(+), 88 deletions(-)
---
diff --git a/stats/fixtures/sample_data.json b/stats/fixtures/sample_data.json
index f9563ae..516fac1 100644
--- a/stats/fixtures/sample_data.json
+++ b/stats/fixtures/sample_data.json
@@ -530,7 +530,19 @@
   "pk": 8, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
+   "untranslated": 128, 
+   "figures": null, 
+   "fuzzy": 0, 
+   "translated": 0, 
+   "path": null
+  }
+ }, 
+ {
+  "pk": 9, 
+  "model": "stats.pofile", 
+  "fields": {
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 0, 
    "figures": null, 
    "fuzzy": 0, 
@@ -539,10 +551,10 @@
   }
  }, 
  {
-  "pk": 9, 
+  "pk": 10, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 6, 
    "figures": null, 
    "fuzzy": 0, 
@@ -551,10 +563,22 @@
   }
  }, 
  {
-  "pk": 10, 
+  "pk": 11, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
+   "untranslated": 28, 
+   "figures": null, 
+   "fuzzy": 0, 
+   "translated": 100, 
+   "path": null
+  }
+ }, 
+ {
+  "pk": 12, 
+  "model": "stats.pofile", 
+  "fields": {
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 259, 
    "figures": null, 
    "fuzzy": 0, 
@@ -563,10 +587,10 @@
   }
  }, 
  {
-  "pk": 11, 
+  "pk": 13, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 259, 
    "figures": null, 
    "fuzzy": 0, 
@@ -575,10 +599,10 @@
   }
  }, 
  {
-  "pk": 12, 
+  "pk": 14, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 0, 
    "figures": null, 
    "fuzzy": 0, 
@@ -587,10 +611,10 @@
   }
  }, 
  {
-  "pk": 13, 
+  "pk": 15, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 149, 
    "figures": null, 
    "fuzzy": 0, 
@@ -599,10 +623,10 @@
   }
  }, 
  {
-  "pk": 14, 
+  "pk": 16, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 0, 
    "figures": null, 
    "fuzzy": 4, 
@@ -611,10 +635,10 @@
   }
  }, 
  {
-  "pk": 15, 
+  "pk": 17, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 0, 
    "figures": null, 
    "fuzzy": 0, 
@@ -623,10 +647,10 @@
   }
  }, 
  {
-  "pk": 16, 
+  "pk": 18, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 259, 
    "figures": null, 
    "fuzzy": 0, 
@@ -635,10 +659,10 @@
   }
  }, 
  {
-  "pk": 17, 
+  "pk": 19, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 259, 
    "figures": null, 
    "fuzzy": 0, 
@@ -647,10 +671,10 @@
   }
  }, 
  {
-  "pk": 18, 
+  "pk": 20, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 0, 
    "figures": null, 
    "fuzzy": 0, 
@@ -659,10 +683,10 @@
   }
  }, 
  {
-  "pk": 19, 
+  "pk": 21, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 626, 
    "figures": null, 
    "fuzzy": 0, 
@@ -671,10 +695,10 @@
   }
  }, 
  {
-  "pk": 20, 
+  "pk": 22, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 2, 
    "figures": null, 
    "fuzzy": 20, 
@@ -683,10 +707,10 @@
   }
  }, 
  {
-  "pk": 21, 
+  "pk": 23, 
   "model": "stats.pofile", 
   "fields": {
-   "updated": "2011-08-08 22:23:57", 
+   "updated": "2011-08-10 14:15:49", 
    "untranslated": 0, 
    "figures": null, 
    "fuzzy": 6, 
@@ -700,7 +724,7 @@
   "fields": {
    "domain": 1, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
    "full_po": 1, 
@@ -715,7 +739,7 @@
   "fields": {
    "domain": 1, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
    "full_po": 2, 
@@ -730,7 +754,7 @@
   "fields": {
    "domain": 1, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
    "full_po": 3, 
@@ -745,7 +769,7 @@
   "fields": {
    "domain": 2, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
    "full_po": 4, 
@@ -760,7 +784,7 @@
   "fields": {
    "domain": 2, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
    "full_po": 5, 
@@ -775,7 +799,7 @@
   "fields": {
    "domain": 2, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
    "full_po": 6, 
@@ -790,12 +814,12 @@
   "fields": {
    "domain": 3, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
    "full_po": 7, 
    "language": null, 
-   "part_po": 7, 
+   "part_po": 8, 
    "branch": 2
   }
  }, 
@@ -805,12 +829,12 @@
   "fields": {
    "domain": 3, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 8, 
+   "full_po": 9, 
    "language": 2, 
-   "part_po": 8, 
+   "part_po": 9, 
    "branch": 2
   }
  }, 
@@ -820,12 +844,12 @@
   "fields": {
    "domain": 3, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 9, 
+   "full_po": 10, 
    "language": 3, 
-   "part_po": 9, 
+   "part_po": 11, 
    "branch": 2
   }
  }, 
@@ -835,12 +859,12 @@
   "fields": {
    "domain": 4, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 10, 
+   "full_po": 12, 
    "language": null, 
-   "part_po": 10, 
+   "part_po": 12, 
    "branch": 2
   }
  }, 
@@ -850,12 +874,12 @@
   "fields": {
    "domain": 4, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 11, 
+   "full_po": 13, 
    "language": 2, 
-   "part_po": 11, 
+   "part_po": 13, 
    "branch": 2
   }
  }, 
@@ -865,12 +889,12 @@
   "fields": {
    "domain": 4, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 12, 
+   "full_po": 14, 
    "language": 3, 
-   "part_po": 12, 
+   "part_po": 14, 
    "branch": 2
   }
  }, 
@@ -880,12 +904,12 @@
   "fields": {
    "domain": 3, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 13, 
+   "full_po": 15, 
    "language": null, 
-   "part_po": 13, 
+   "part_po": 15, 
    "branch": 3
   }
  }, 
@@ -895,12 +919,12 @@
   "fields": {
    "domain": 3, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 14, 
+   "full_po": 16, 
    "language": 2, 
-   "part_po": 14, 
+   "part_po": 16, 
    "branch": 3
   }
  }, 
@@ -910,12 +934,12 @@
   "fields": {
    "domain": 3, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 15, 
+   "full_po": 17, 
    "language": 3, 
-   "part_po": 15, 
+   "part_po": 17, 
    "branch": 3
   }
  }, 
@@ -925,12 +949,12 @@
   "fields": {
    "domain": 4, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 16, 
+   "full_po": 18, 
    "language": null, 
-   "part_po": 16, 
+   "part_po": 18, 
    "branch": 3
   }
  }, 
@@ -940,12 +964,12 @@
   "fields": {
    "domain": 4, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 17, 
+   "full_po": 19, 
    "language": 2, 
-   "part_po": 17, 
+   "part_po": 19, 
    "branch": 3
   }
  }, 
@@ -955,12 +979,12 @@
   "fields": {
    "domain": 4, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 18, 
+   "full_po": 20, 
    "language": 3, 
-   "part_po": 18, 
+   "part_po": 20, 
    "branch": 3
   }
  }, 
@@ -970,12 +994,12 @@
   "fields": {
    "domain": 5, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 19, 
+   "full_po": 21, 
    "language": null, 
-   "part_po": 19, 
+   "part_po": 21, 
    "branch": 4
   }
  }, 
@@ -985,12 +1009,12 @@
   "fields": {
    "domain": 5, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 20, 
+   "full_po": 22, 
    "language": 2, 
-   "part_po": 20, 
+   "part_po": 22, 
    "branch": 4
   }
  }, 
@@ -1000,12 +1024,12 @@
   "fields": {
    "domain": 5, 
    "old_translated": 0, 
-   "old_date": "2011-08-08 22:23:57", 
+   "old_date": "2011-08-10 14:15:49", 
    "old_fuzzy": 0, 
    "old_untranslated": 0, 
-   "full_po": 21, 
+   "full_po": 23, 
    "language": 3, 
-   "part_po": 21, 
+   "part_po": 23, 
    "branch": 4
   }
  }, 
diff --git a/stats/models.py b/stats/models.py
index 16e7902..4c8ceef 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1660,9 +1660,13 @@ class FakeLangStatistics(object):
         }
 
     def po_url(self, potfile=False, reduced=False):
+        if reduced:
+            locale = "%s-reduced" % self.language.locale
+        else:
+            locale = self.language.locale
         return reverse(
             'dynamic_po',
-            args=("%s.%s.%s.%s.po" % (self.branch.module.name, self.domain.name, self.branch.name, self.language.locale),)
+            args=("%s.%s.%s.%s.po" % (self.branch.module.name, self.domain.name, self.branch.name, locale),)
         )
 
 class FakeSummaryStatistics(object):
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index 108cbe3..a61eb88 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -27,7 +27,7 @@ from django.core.exceptions import ValidationError
 from django.core.urlresolvers import reverse
 from django.conf import settings
 
-from stats.models import Module, Domain, Branch, Category, Release, Statistics, Information
+from stats.models import Module, Domain, Branch, Category, Release, Statistics, FakeLangStatistics, Information
 from stats.utils import check_program_presence, run_shell_command
 from languages.models import Language
 
@@ -226,16 +226,16 @@ class ModuleTestCase(TestCase):
 
     def testDynamicPO(self):
         """ Test the creation of a blank po file for a new language """
-        lang = Language(name="Tamil", locale="ta")
-        lang.save()
+        lang = Language.objects.create(name="Tamil", locale="ta")
         self.b.update_stats(force=True) # At least POT stats needed
-        c = Client()
-        response = c.get('/module/po/gnome-hello.po.master.ta.po')
+        response = self.client.get('/module/po/gnome-hello.po.master.ta.po')
         self.assertContains(response, """# Tamil translation for gnome-hello.
 # Copyright (C) %s gnome-hello's COPYRIGHT HOLDER
 # This file is distributed under the same license as the gnome-hello package.
 # FIRST AUTHOR <EMAIL ADDRESS>, YEAR.""" % date.today().year)
         self.assertContains(response, "Language-Team: Tamil <ta li org>")
+        response = self.client.get('/module/po/gnome-hello.po.master.ta-reduced.po')
+        self.assertContains(response, """# Tamil translation for gnome-hello.""")
 
     @test_scratchdir
     def testBranchFileChanged(self):
@@ -267,6 +267,21 @@ class StatisticsTests(TestCase):
     def testTotalStatsForLang(self):
         rel  = Release.objects.get(name="gnome-2-30")
         total_for_lang = rel.total_for_lang(Language.objects.get(locale='fr'))
-        self.assertEqual(total_for_lang['uitotal'], total_for_lang['uitotal_part'])
+        self.assertEqual(total_for_lang['uitotal']-8, total_for_lang['uitotal_part'])
         total_for_lang = rel.total_for_lang(Language.objects.get(locale='bem'))
-        self.assertEqual(total_for_lang['uitotal'], total_for_lang['uitotal_part'])
+        self.assertEqual(total_for_lang['uitotal']-8, total_for_lang['uitotal_part'])
+
+    def testStatsLinks(self):
+        pot_stats = Statistics.objects.get(
+            branch__module__name='zenity', branch__name='gnome-2-30',
+            domain__name='po', language__isnull=True)
+        self.assertEqual(pot_stats.po_url(), "/POT/zenity.gnome-2-30/zenity.gnome-2-30.pot")
+        stats = Statistics.objects.get(
+            branch__module__name='zenity', branch__name='gnome-2-30',
+            domain__name='po', language__locale='it')
+        self.assertEqual(stats.po_url(), "/POT/zenity.gnome-2-30/zenity.gnome-2-30.it.po")
+        self.assertEqual(stats.po_url(reduced=True), "/POT/zenity.gnome-2-30/zenity.gnome-2-30.it.reduced.po")
+        # Same for a fake stats
+        stats = FakeLangStatistics(pot_stats, Language.objects.get(locale='bem'))
+        self.assertEqual(stats.po_url(), "/module/po/zenity.po.gnome-2-30.bem.po")
+        self.assertEqual(stats.po_url(reduced=True), "/module/po/zenity.po.gnome-2-30.bem-reduced.po")
diff --git a/stats/tests/fixture_factory.py b/stats/tests/fixture_factory.py
index 521fe6f..9563df8 100644
--- a/stats/tests/fixture_factory.py
+++ b/stats/tests/fixture_factory.py
@@ -122,11 +122,13 @@ class FixtureFactory(TestCase):
         Statistics.objects.create(branch=b1, domain=dom['gnome-hello-doc'], language=l_it, full_po=pofile, part_po=pofile)
         # zenity ui 2.30, zenity doc 2.30, zenity ui master, zenity doc master (POT, fr, it)
         pofile = PoFile.objects.create(untranslated=136)
-        Statistics.objects.create(branch=b2, domain=dom['zenity-ui'], language=None, full_po=pofile, part_po=pofile)
+        part_pofile = PoFile.objects.create(untranslated=128)
+        Statistics.objects.create(branch=b2, domain=dom['zenity-ui'], language=None, full_po=pofile, part_po=part_pofile)
         pofile = PoFile.objects.create(translated=136)
         Statistics.objects.create(branch=b2, domain=dom['zenity-ui'], language=l_fr, full_po=pofile, part_po=pofile)
         pofile = PoFile.objects.create(translated=130, untranslated=6)
-        Statistics.objects.create(branch=b2, domain=dom['zenity-ui'], language=l_it, full_po=pofile, part_po=pofile)
+        part_pofile = PoFile.objects.create(translated=100, untranslated=28)
+        Statistics.objects.create(branch=b2, domain=dom['zenity-ui'], language=l_it, full_po=pofile, part_po=part_pofile)
         pofile = PoFile.objects.create(untranslated=259)
         Statistics.objects.create(branch=b2, domain=dom['zenity-doc'], language=None, full_po=pofile, part_po=pofile)
         pofile = PoFile.objects.create(untranslated=259)
diff --git a/stats/views.py b/stats/views.py
index 124682a..b648aa1 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -172,6 +172,10 @@ def dynamic_po(request, filename):
     """ Generates a dynamic po file from the POT file of a branch """
     try:
         module, domain, branch, locale, ext = filename.split(".")
+        if locale.endswith('-reduced'):
+            locale, reduced = locale[:-8], True
+        else:
+            reduced = False
         language = Language.objects.select_related('team').get(locale=locale)
     except:
         raise Http404
@@ -180,7 +184,7 @@ def dynamic_po(request, filename):
                              branch__name=branch,
                              domain__name=domain,
                              language=None)
-    file_path = potfile.po_path().encode('ascii')
+    file_path = potfile.po_path(reduced=reduced).encode('ascii')
     if not os.access(file_path, os.R_OK):
         raise Http404
 



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