diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-10-28 20:26:31 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-10-28 20:26:31 +0200 |
commit | 95c7286324b93564e1c996f18a4f1614a4ee6f1d (patch) | |
tree | 3652f3dcb6991a052ec6a1c9ec2e89f0038a5cd0 | |
parent | 6f80a494ceac19d5db0650a591bf112b09ea2eba (diff) | |
download | Ishtar-95c7286324b93564e1c996f18a4f1614a4ee6f1d.tar.bz2 Ishtar-95c7286324b93564e1c996f18a4f1614a4ee6f1d.zip |
Force regeneration of cached labels when add M2M or changing ids
-rw-r--r-- | archaeological_context_records/models.py | 1 | ||||
-rw-r--r-- | archaeological_files/models.py | 5 | ||||
-rw-r--r-- | archaeological_files/tests.py | 14 | ||||
-rw-r--r-- | archaeological_finds/models.py | 4 | ||||
-rw-r--r-- | example_project/settings.py | 3 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 4 |
6 files changed, 28 insertions, 3 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 7df766f2f..3f4dc1598 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -364,6 +364,7 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return returned diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 623eb1dee..1d8317b31 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -521,6 +521,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return returned @@ -536,9 +537,9 @@ post_save.connect(cached_label_changed, sender=File) class FileByDepartment(models.Model): - ''' + """ Database view for dashboard - ''' + """ file = models.ForeignKey(File, verbose_name=_(u"File")) department = models.ForeignKey(Department, verbose_name=_(u"Department"), blank=True, null=True) diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index dfaa1fb09..4a09e1caa 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -86,6 +86,20 @@ class FileTest(TestCase, FileInit): u"{}-{}".format(self.item.year, self.item.numeric_reference)) + def testCachedLabel(self): + lbls = ['No town', self.item.external_id, + self.item.internal_reference] + lbl = settings.JOINT.join(lbls) + self.assertEqual(self.item.cached_label, lbl) + default_town = Town.objects.create(name="Paris", numero_insee='75001') + self.item.towns.add(default_town) + # manually done inside wizards + self.item._cached_label_checked = False + self.item.save() + lbls[0] = "Paris" + lbl = settings.JOINT.join(lbls) + self.assertEqual(self.item.cached_label, lbl) + def testAddAndGetHistorized(self): """ Test correct new version and correct access to history diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 5799d0e9a..aa5eacc30 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -269,6 +269,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms): self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return returned @@ -653,6 +654,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return @@ -671,6 +673,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): self.index = q.aggregate(Max('index'))['index__max'] + 1 else: self.index = 1 + self._cached_label_checked = False self.save() for base_find in self.base_finds.filter( context_record__operation__pk__isnull=False).all(): @@ -689,6 +692,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): modified = True if modified: base_find.skip_history_when_saving = True + base_find._cached_label_checked = False base_find.save() # if not base_find.material_index: # idx = BaseFind.objects\ diff --git a/example_project/settings.py b/example_project/settings.py index ef52d932a..a191b83b3 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -288,3 +288,6 @@ if SQL_DEBUG: 'level': 'DEBUG', 'handlers': ['console'], } + +if 'test' in sys.argv: + PROJECT_SLUG += "-test" diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index c8467ca61..c065459f6 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -553,6 +553,7 @@ class Wizard(NamedUrlWizardView): getattr(obj, k).add(adds[k]) # necessary to manage interaction between models like # material_index management for baseitems + obj._cached_label_checked = False obj.save() m2m_items = {} # clear @@ -618,6 +619,7 @@ class Wizard(NamedUrlWizardView): related_model.add(value) # necessary to manage interaction between models like # material_index management for baseitems + obj._cached_label_checked = False obj.save() # make the new object a default if self.current_obj_slug: @@ -715,7 +717,7 @@ class Wizard(NamedUrlWizardView): # and self.form_initialized: # for k in init[0]: # data[step + '-' + unicode(total_field) + '-' + k] = \ - # init[0][k] + # init[0][k] data = data or None form = super(Wizard, self).get_form(step, data, files) |