diff options
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 24 | 
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', | 
