summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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
commitf296333a87085ee0e04a0f4fbfc207c112f17bce (patch)
tree3652f3dcb6991a052ec6a1c9ec2e89f0038a5cd0
parent328de388cf7c8cd213752c01dfadc2a19e8acb6f (diff)
downloadIshtar-f296333a87085ee0e04a0f4fbfc207c112f17bce.tar.bz2
Ishtar-f296333a87085ee0e04a0f4fbfc207c112f17bce.zip
Force regeneration of cached labels when add M2M or changing ids
-rw-r--r--archaeological_context_records/models.py1
-rw-r--r--archaeological_files/models.py5
-rw-r--r--archaeological_files/tests.py14
-rw-r--r--archaeological_finds/models.py4
-rw-r--r--example_project/settings.py3
-rw-r--r--ishtar_common/wizards.py4
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)