diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/tests.py | 9 | ||||
| -rw-r--r-- | ishtar_common/views.py | 19 | 
2 files changed, 27 insertions, 1 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 349408465..8a951b29a 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1046,6 +1046,15 @@ class IshtarBasicTest(TestCase):          self.assertEqual(response.status_code, 200)          self.assertIn('class="sheet"', response.content) +    def test_town_cache(self): +        models.Town.objects.create(name="Sin City", numero_insee="99999") +        town = models.Town.objects.get(numero_insee="99999") +        self.assertEqual(town.cached_label, "Sin City - 99") +        town.year = 2050 +        town.save() +        town = models.Town.objects.get(numero_insee="99999") +        self.assertEqual(town.cached_label, "Sin City - 99 (2050)") +  class GeomaticTest(TestCase):      def test_post_save_point(self): diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 6652ba6a9..b8350c62a 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -815,6 +815,23 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                      dct.pop(k)          # manage hierarchic conditions          for req in dct.copy(): +            if req.endswith('town__pk') or req.endswith('towns__pk'): +                val = dct.pop(req) +                reqs = Q(**{req: val}) +                base_req = req[:-2] + '__' +                req = base_req[:] +                for idx in range(HIERARCHIC_LEVELS): +                    req = req[:-2] + 'parents__pk' +                    q = Q(**{req: val}) +                    reqs |= q +                req = base_req[:] +                for idx in range(HIERARCHIC_LEVELS): +                    req = req[:-2] + 'children__pk' +                    q = Q(**{req: val}) +                    reqs |= q +                and_reqs.append(reqs) +                continue +              for k_hr in HIERARCHIC_FIELDS:                  if type(req) in (list, tuple):                      val = dct.pop(req) @@ -830,7 +847,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                      val = dct.pop(req)                      reqs = Q(**{req: val})                      req = req[:-2] + '__' -                    for idx in xrange(HIERARCHIC_LEVELS): +                    for idx in range(HIERARCHIC_LEVELS):                          req = req[:-2] + 'parent__pk'                          q = Q(**{req: val})                          reqs |= q  | 
