diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-07-14 19:07:14 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-07-14 19:07:14 +0200 |
commit | 2ec9da827e25557d89266044038f98a7f3c6c08d (patch) | |
tree | aef2cc7fa68301c5043b92082c1b60f137917786 /archaeological_operations/models.py | |
parent | 82339d572e8a414049f3b5eef1c51e7c3d3f8d95 (diff) | |
download | Ishtar-2ec9da827e25557d89266044038f98a7f3c6c08d.tar.bz2 Ishtar-2ec9da827e25557d89266044038f98a7f3c6c08d.zip |
Fix simulatneous operation_code creation
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 8b083d4be..c6e55f03b 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -573,14 +573,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): template = q.all()[0] return template.publish(self) - def save(self, *args, **kwargs): - if not self.signature_date: - return super(AdministrativeAct, self).save(*args, **kwargs) - self.year = self.signature_date.year - - if not self.act_type.indexed: - return super(AdministrativeAct, self).save(*args, **kwargs) - + def _get_index(self): if not self.index: c_index = 1 q = AdministrativeAct.objects.filter(act_type__indexed=True, @@ -595,8 +588,21 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): if self.pk: conflict = conflict.exclude(pk=self.pk) if conflict.count(): - raise ValidationError(_(u"This index already exists for " - u"this year")) + if self.pk: + raise ValidationError(_(u"This index already exists for " + u"this year")) + else: + self._get_index() + + def save(self, *args, **kwargs): + if not self.signature_date: + return super(AdministrativeAct, self).save(*args, **kwargs) + self.year = self.signature_date.year + + if not self.act_type.indexed: + return super(AdministrativeAct, self).save(*args, **kwargs) + + self._get_index() super(AdministrativeAct, self).save(*args, **kwargs) class Parcel(LightHistorizedItem): |