diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-11-17 16:43:23 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-11-17 16:43:23 +0100 |
commit | e3111cbaade142c79671947ca26bc8e036bf95ea (patch) | |
tree | 448edbb065b37ff7e93b75faeb62e0c45701283b /archaeological_operations/models.py | |
parent | 95adfd6ad89f225e3ead9389bfec4825b75ede10 (diff) | |
download | Ishtar-e3111cbaade142c79671947ca26bc8e036bf95ea.tar.bz2 Ishtar-e3111cbaade142c79671947ca26bc8e036bf95ea.zip |
Operations: towns and deparments in columns
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 0b974ecf8..6fba0d7b3 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -523,12 +523,18 @@ AdministrativeAct = None if FILES_AVAILABLE: class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'act_object', - 'signature_date', 'associated_file', 'operation'] - TABLE_COLS_FILE = ['full_ref', 'year', 'index', 'act_type', - 'act_object', 'associated_file', - 'associated_file.towns', ] + 'signature_date', 'associated_file', 'operation', + 'towns_label'] + TABLE_COLS_FILE = [ + 'full_ref', 'year', 'index', 'act_type', + 'act_object', 'associated_file', 'towns_label', + ] TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation', - 'act_object', 'operation.towns'] + 'act_object', 'towns_label'] + if settings.COUNTRY == 'fr': + TABLE_COLS.append('departments_label') + TABLE_COLS_FILE.append('departments_label') + TABLE_COLS_OPE.append('departments_label') act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type")) in_charge = models.ForeignKey( Person, blank=True, null=True, @@ -565,6 +571,12 @@ if FILES_AVAILABLE: if settings.COUNTRY == 'fr': ref_sra = models.CharField(u"Référence SRA", max_length=15, blank=True, null=True) + departments_label = models.TextField( + _(u"Departments"), blank=True, null=True, + help_text=_(u"Cached values get from associated departments")) + towns_label = models.TextField( + _(u"Towns"), blank=True, null=True, + help_text=_(u"Cached values get from associated towns")) history = HistoricalRecords() _prefix = 'adminact_' @@ -611,7 +623,24 @@ if FILES_AVAILABLE: elif self.operation: return self.operation.towns.all() return [] - towns_lbl = _(u"Towns") + + @property + def departments(self): + if settings.COUNTRY != 'fr': + return '' + q = None + if self.associated_file: + q = self.associated_file.towns.all() + elif self.operation: + q = self.operation.towns.all() + if not q: + return '' + dpts = [] + for town in q: + dpt = town.numero_insee[:2] + if dpt not in dpts: + dpts.append(dpt) + return ', '.join(list(sorted(dpts))) @property def related_item(self): @@ -672,6 +701,15 @@ if FILES_AVAILABLE: super(AdministrativeAct, self).clean(*args, **kwargs) def save(self, *args, **kwargs): + if settings.COUNTRY == 'fr': + self.departments_label = self.departments + self.towns_label = u", ".join( + list(sorted([unicode(town) for town in self.towns]))) + + force = False + if 'force' in kwargs: + force = kwargs.pop('force') + if not self.signature_date: return super(AdministrativeAct, self).save(*args, **kwargs) self.year = self.signature_date.year @@ -679,7 +717,14 @@ if FILES_AVAILABLE: if not self.act_type.indexed: return super(AdministrativeAct, self).save(*args, **kwargs) - self._get_index() + if not force: + self._get_index() + else: + try: + self._get_index() + except: + pass + super(AdministrativeAct, self).save(*args, **kwargs) if hasattr(self, 'associated_file') and self.associated_file: self.associated_file.update_has_admin_act() |