diff options
Diffstat (limited to 'archaeological_files/models.py')
| -rw-r--r-- | archaeological_files/models.py | 15 | 
1 files changed, 10 insertions, 5 deletions
| diff --git a/archaeological_files/models.py b/archaeological_files/models.py index fa10036b0..9709824df 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -31,7 +31,7 @@ from ishtar_common.utils import cached_label_changed, get_cache  from ishtar_common.models import GeneralType, BaseHistorizedItem, \      HistoricalRecords, OwnPerms, Person, Organization, Department, Town, \      Dashboard, DashboardFormItem, IshtarUser, ValueGetter, ShortMenuItem, \ -    OperationType +    OperationType, get_external_id  from archaeological_operations.models import get_values_town_related @@ -80,6 +80,8 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,                                            null=True, max_length=60)      external_id = models.CharField(_(u"External ID"), blank=True, null=True,                                     max_length=120) +    auto_external_id = models.BooleanField( +        _(u"External ID is set automatically"), default=False)      name = models.TextField(_(u"Name"), blank=True, null=True)      file_type = models.ForeignKey(FileType, verbose_name=_(u"File type"))      in_charge = models.ForeignKey(Person, related_name='file_responsability', @@ -331,7 +333,7 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,      @classmethod      def get_owns(cls, user):          owns = super(File, cls).get_owns(user) -        return sorted(owns.all(), key=lambda x: x.cached_label) +        return sorted(owns, key=lambda x: x.cached_label)      def get_values(self, prefix=''):          values = super(File, self).get_values(prefix=prefix) @@ -491,14 +493,17 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,          self.update_resp_planning_service()          updated += self.update_raw_general_contractor()          updated += self.update_corpo_general_contractor() -        if self.year and self.numeric_reference: -            external_id = u"{}{}-{}".format(settings.ISHTAR_LOCAL_PREFIX, -                                            self.year, self.numeric_reference) + +        if not self.external_id or self.auto_external_id: +            external_id = get_external_id('file_external_id', self)              if external_id != self.external_id:                  updated = True +                self.auto_external_id = True                  self.external_id = external_id          if updated:              self.save() +            return returned +          self.update_delay_date()          self.update_short_menu_class()          return returned | 
