diff options
Diffstat (limited to 'archaeological_files/models.py')
-rw-r--r-- | archaeological_files/models.py | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 0258cb16d..1cfbe35d3 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -31,9 +31,10 @@ 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 +from archaeological_operations.models import get_values_town_related, \ + ClosedItem class FileType(GeneralType): @@ -68,8 +69,8 @@ if settings.COUNTRY == 'fr': ordering = ('label',) -class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, - DashboardFormItem): +class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, + ShortMenuItem, DashboardFormItem): TABLE_COLS = ['numeric_reference', 'year', 'internal_reference', 'file_type', 'saisine_type', 'towns', ] year = models.IntegerField(_(u"Year"), @@ -80,6 +81,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', @@ -133,9 +136,9 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, verbose_name=u"Type de saisine") instruction_deadline = models.DateField(_(u'Instruction deadline'), blank=True, null=True) - total_surface = models.IntegerField(_(u"Total surface (m2)"), - blank=True, null=True) - total_developed_surface = models.IntegerField( + total_surface = models.FloatField(_(u"Total surface (m2)"), + blank=True, null=True) + total_developed_surface = models.FloatField( _(u"Total developed surface (m2)"), blank=True, null=True) locality = models.CharField(_(u"Locality"), max_length=100, null=True, blank=True) @@ -394,18 +397,6 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, def town_list(self): return u", ".join([unicode(tw) for tw in self.towns.all()]) - def closing(self): - if self.is_active(): - return - q = self.history - if not q.count(): - return {'date': None, 'user': None} - for item in q.all(): - if not item.end_date: - break - return {'date': item.history_date, - 'user': IshtarUser.objects.get(pk=item.history_modifier_id)} - def total_surface_ha(self): if self.total_surface: return self.total_surface / 10000.0 @@ -491,14 +482,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 |