summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-27 11:33:52 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-27 11:33:52 +0100
commit9e058ac03ca182a85d26590960c1e0b0206663cd (patch)
tree94380717ffc10090011d773029e0e651c3cb6bc8 /archaeological_operations/models.py
parent82bec7af1d41ea884fa4961fee017fbbc7f99470 (diff)
downloadIshtar-9e058ac03ca182a85d26590960c1e0b0206663cd.tar.bz2
Ishtar-9e058ac03ca182a85d26590960c1e0b0206663cd.zip
Manage index for administrativ act: model, automatic indexation (refs #1587)
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 9edbb382c..7648dd6bf 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -383,6 +383,7 @@ class ActType(GeneralType):
associated_template = models.ManyToManyField(DocumentTemplate, blank=True,
null=True, verbose_name=_(u"Associated template"),
related_name='acttypes')
+ indexed = models.BooleanField(_(u"Indexed"), default=False)
class Meta:
verbose_name = _(u"Act type")
verbose_name_plural = _(u"Act types")
@@ -396,6 +397,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
in_charge = models.ForeignKey(Person, blank=True, null=True,
related_name='+', verbose_name=_(u"Person in charge of the operation"))
+ index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True)
operator = models.ForeignKey(Organization, blank=True, null=True,
verbose_name=_(u"Archaeological preventive operator"))
scientific = models.ForeignKey(Person, blank=True, null=True,
@@ -464,6 +466,28 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
template = q.all()[0]
return template.publish(self)
+ def save(self, *args, **kwargs):
+ if not self.act_type.indexed or not self.signature_date:
+ super(AdministrativeAct, self).save(*args, **kwargs)
+ year = self.signature_date.year
+ if not self.index:
+ c_index = 1
+ q = AdministrativeAct.objects.filter(act_type__indexed=True,
+ signature_date__year=year).order_by("-index")
+ if q.count():
+ c_index = q.all()[0].index
+ self.index = c_index
+ if self.act_type.indexed:
+ conflict = AdministrativeAct.objects.filter(act_type__indexed=True,
+ signature_date__year=year
+ index=self.index)
+ if self.pk:
+ conflict = conflict.exclude(pk=self.pk)
+ if conflict.count():
+ raise ValidationError(_(u"This index already exists for "
+ u"this year"))
+ super(AdministrativeAct, self).save(*args, **kwargs)
+
class Parcel(LightHistorizedItem):
if FILES_AVAILABLE:
associated_file = models.ForeignKey(File, related_name='parcels',