[damned-lies] Updated syntax



commit 960dc756b659cc57e1a74a1ea3bf576ff172f33a
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Feb 6 16:10:04 2014 +0100

    Updated syntax

 stats/models.py |   47 +++++++++++++++++++++--------------------------
 1 files changed, 21 insertions(+), 26 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index dbfe4d6..5994f70 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -435,14 +435,13 @@ class Branch(models.Model):
                 # Prepare statistics object
                 try:
                     pot_stat = Statistics.objects.get(language=None, branch=self, domain=dom)
-                    Information.objects.filter(statistics=pot_stat).delete() # Reset errors
+                    pot_stat.information_set.all().delete()  # Reset errors
                 except Statistics.DoesNotExist:
-                    pot_stat = Statistics(language=None, branch=self, domain=dom)
-                    pot_stat.save()
+                    pot_stat = Statistics.objects.create(language=None, branch=self, domain=dom)
 
                 # 4. Compare with old pot files, various checks
                 # *****************************
-                previous_pot = os.path.join(self.output_dir(dom.dtype), dom.potbase() + "." + self.name + 
".pot")
+                previous_pot = os.path.join(self.output_dir(dom.dtype), '%s.%s.pot' % (dom.potbase(), 
self.name))
                 if not potfile:
                     logging.error("Can't generate POT file for %s/%s." % (
                         self.module.name, dom.directory))
@@ -524,20 +523,18 @@ class Branch(models.Model):
                             language = Language.objects.get(locale=lang)
                         except Language.DoesNotExist:
                             if self.is_head():
-                                language = Language(name=lang, locale=lang)
-                                language.save()
+                                language = Language.objects.create(name=lang, locale=lang)
                             else:
                                 # Do not create language (and therefore ignore stats) for an 'old' branch
                                 continue
-                        stat = Statistics(language = language, branch = self, domain = dom)
-                        stat.save()
+                        stat = Statistics.objects.create(language=language, branch=self, domain=dom)
                     stat.set_translation_stats(outpo,
-                                               translated = int(langstats['translated']),
-                                               fuzzy = int(langstats['fuzzy']),
-                                               untranslated = int(langstats['untranslated']),
-                                               translated_words = int(langstats['translated_words']),
-                                               fuzzy_words = int(langstats['fuzzy_words']),
-                                               untranslated_words = int(langstats['untranslated_words']),
+                                               translated=int(langstats['translated']),
+                                               fuzzy=int(langstats['fuzzy']),
+                                               untranslated=int(langstats['untranslated']),
+                                               translated_words=int(langstats['translated_words']),
+                                               fuzzy_words=int(langstats['fuzzy_words']),
+                                               untranslated_words=int(langstats['untranslated_words']),
                                                figstats=fig_stats)
                     for err in langstats['errors']:
                         stat.information_set.add(Information(type=err[0], description=err[1]))
@@ -1354,9 +1351,7 @@ class Statistics(models.Model):
         unique_together = ('branch', 'domain', 'language')
 
     def __init__(self, *args, **kwargs):
-        models.Model.__init__(self, *args, **kwargs)
-        self.modname = None
-        self.moddescription = None
+        super(Statistics, self).__init__(*args, **kwargs)
         self.partial_po = False # True if part of a multiple po module
         self.info_list = []
 
@@ -1440,15 +1435,13 @@ class Statistics(models.Model):
         else:
             return "pot file"
 
+    @property
     def module_name(self):
-        if not self.modname:
-            self.modname = self.branch.module.name
-        return self.modname
+        return self.branch.module.name
 
+    @property
     def module_description(self):
-        if not self.moddescription:
-            self.moddescription = self.branch.module.description or self.branch.module.name
-        return self.moddescription
+        return self.branch.module.description or self.branch.module.name
 
     def has_reducedstat(self):
         return bool(self.part_po is not None and self.part_po != self.full_po)
@@ -1530,7 +1523,8 @@ class Statistics(models.Model):
         subdir = ""
         if self.domain.dtype == "doc":
             subdir = "docs"
-        path = os.path.join(settings.POTDIR, self.module_name()+'.'+self.branch.name, subdir, 
self.filename(potfile, reduced))
+        path = os.path.join(settings.POTDIR, "%s.%s" % (self.module_name, self.branch.name),
+            subdir, self.filename(potfile, reduced))
         if reduced and not os.path.exists(path):
             path = self.po_path(potfile=potfile, reduced=False)
         return path
@@ -1540,7 +1534,8 @@ class Statistics(models.Model):
         subdir = ""
         if self.domain.dtype == "doc":
             subdir = "docs/"
-        return utils.url_join("/POT/", "%s.%s" % (self.module_name(), self.branch.name), subdir, 
self.filename(potfile, reduced))
+        return utils.url_join("/POT/", "%s.%s" % (self.module_name, self.branch.name),
+            subdir, self.filename(potfile, reduced))
 
     def pot_url(self):
         return self.po_url(potfile=True)
@@ -1904,7 +1899,7 @@ class Information(models.Model):
         return info_dict
 
     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 "%simg/%s.png" % (settings.STATIC_URL, self.type.split("-")[0])


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