summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_finds.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-20 13:45:27 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-20 13:45:27 +0200
commitf46de1b6d4cbf832ce6f22fe82a5377b5e0ed6a4 (patch)
treefd072535b325d65f12e415e6582cf7a073775999 /archaeological_finds/models_finds.py
parent782b857248435767cc4868a472ce27211596614a (diff)
downloadIshtar-f46de1b6d4cbf832ce6f22fe82a5377b5e0ed6a4.tar.bz2
Ishtar-f46de1b6d4cbf832ce6f22fe82a5377b5e0ed6a4.zip
Fix external id generation for finds
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r--archaeological_finds/models_finds.py37
1 files changed, 10 insertions, 27 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 8a7dbaf08..be563f34e 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -33,8 +33,8 @@ from ishtar_common.utils import cached_label_changed, post_save_point
from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \
ShortMenuItem, LightHistorizedItem, HistoricalRecords, OwnPerms, Source, \
- Person, Basket, get_external_id, post_save_cache, ValueGetter, \
- get_current_profile
+ Person, Basket, post_save_cache, ValueGetter, \
+ get_current_profile, ExternalIdManager
from archaeological_operations.models import AdministrativeAct
from archaeological_context_records.models import ContextRecord, Dating
@@ -150,7 +150,10 @@ class BFBulkView(object):
"""
-class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms):
+class BaseFind(ExternalIdManager, BulkUpdatedItem, BaseHistorizedItem,
+ OwnPerms):
+ EXTERNAL_ID_KEY = 'base_find_external_id'
+ EXTERNAL_ID_DEPENDENCIES = ['find']
label = models.TextField(_(u"Free ID"))
external_id = models.TextField(_(u"External ID"), blank=True, null=True)
auto_external_id = models.BooleanField(
@@ -327,21 +330,6 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms):
def name(self):
return self.label
- def save(self, *args, **kwargs):
- returned = super(BaseFind, self).save(*args, **kwargs)
-
- updated = False
- if not self.external_id or self.auto_external_id:
- external_id = get_external_id('base_find_external_id', self)
- if external_id != self.external_id:
- updated = True
- self.auto_external_id = True
- self.external_id = external_id
- if updated:
- self._cached_label_checked = False
- self.save()
- return returned
-
@classmethod
def cached_label_bulk_update(cls, operation_id=None, parcel_id=None,
context_record_id=None, transaction_id=None):
@@ -506,8 +494,9 @@ class FBulkView(object):
"""
-class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,
- OwnPerms, ShortMenuItem):
+class Find(ExternalIdManager, BulkUpdatedItem, ValueGetter,
+ BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
+ EXTERNAL_ID_KEY = 'find_external_id'
CHECK_DICT = dict(CHECK_CHOICES)
SHOW_URL = 'show-find'
SLUG = 'find'
@@ -1161,14 +1150,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,
def save(self, *args, **kwargs):
super(Find, self).save(*args, **kwargs)
- updated = False
self.skip_history_when_saving = True
- if not self.external_id or self.auto_external_id:
- external_id = get_external_id('find_external_id', self)
- if external_id != self.external_id:
- updated = True
- self.auto_external_id = True
- self.external_id = external_id
+ updated = self.update_external_id(save=False)
if updated:
self._cached_label_checked = False
self.save()