[damned-lies] Filter domains in Statistics.get_lang_stats_by_type
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Filter domains in Statistics.get_lang_stats_by_type
- Date: Sat, 3 Oct 2015 13:30:36 +0000 (UTC)
commit 025fd830c895fe0677594f8ec475370cd6606d11
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Oct 3 15:30:23 2015 +0200
Filter domains in Statistics.get_lang_stats_by_type
stats/models.py | 14 +++++++++++---
stats/tests/tests.py | 2 ++
2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index d3daa71..b1dcac4 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -350,11 +350,17 @@ class Branch(models.Model):
"""
domains = OrderedDict()
for dom in Domain.objects.filter(module=self.module).select_related('branch_from',
'branch_to').all():
- if (dom.branch_from and self > dom.branch_from) or (dom.branch_to and self < dom.branch_to):
- continue
- domains[dom.name] = dom
+ if self.has_domain(dom):
+ domains[dom.name] = dom
return domains
+ def has_domain(self, domain):
+ # generate query only if branch_from/branch_to are defined.
+ if (domain.branch_from_id or domain.branch_to_id):
+ if (domain.branch_from and self > domain.branch_from) or (domain.branch_to and self <
domain.branch_to):
+ return False
+ return True
+
def domain_path(self, domain):
return os.path.join(self.co_path(), domain.directory)
@@ -1684,6 +1690,8 @@ class Statistics(models.Model):
vt_state.last_comment = actions_dict[vt_state.id].comment
for stat in pot_stats:
+ if not stat.branch.has_domain(stat.domain):
+ continue
categ_key = "Default"
if release:
categ_key = categ_names.get(stat.branch_id)
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 755805c..840b4c0 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -135,6 +135,8 @@ class ModuleTestCase(TestCase):
help_domain.branch_from = b5
help_domain.save()
self.assertEqual(list(b3.get_domains().keys()), ['po'])
+ self.assertFalse(b3.has_domain(help_domain))
+ self.assertTrue(b3.has_domain(domains['po']))
self.assertEqual(list(b5.get_domains().keys()), ['po', 'help'])
help_domain.branch_to = b7
help_domain.save()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]