diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-06-15 20:53:49 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-06-15 20:53:49 +0200 |
commit | b46744b1f77d543452d78fe6da9d5ddaccd11461 (patch) | |
tree | 887e59ec83362110d807c99068ce0023de673732 /archaeological_operations/models.py | |
parent | 3450d1a1f479007e26f87f5a9d31fded11ca7f2b (diff) | |
download | Ishtar-b46744b1f77d543452d78fe6da9d5ddaccd11461.tar.bz2 Ishtar-b46744b1f77d543452d78fe6da9d5ddaccd11461.zip |
Fix default ordering of admin acts - add a year value to better query (refs #1680)
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 2ea29fcf5..8af6b123d 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -463,11 +463,12 @@ class ActType(GeneralType): ordering = ('label',) class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): - TABLE_COLS = ['full_ref', 'act_type', 'signature_date', + TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'signature_date', 'associated_file', 'operation'] - TABLE_COLS_FILE = ['full_ref', 'act_type', 'associated_file', + TABLE_COLS_FILE = ['full_ref', 'year', 'index', 'act_type', 'associated_file', 'associated_file.towns',] - TABLE_COLS_OPE = ['full_ref', 'act_type', 'operation', 'operation.towns'] + TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation', + 'operation.towns'] act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type")) in_charge = models.ForeignKey(Person, blank=True, null=True, related_name='adminact_operation_in_charge', @@ -493,6 +494,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): verbose_name=_(u"Archaelogical file")) signature_date = models.DateField(_(u"Signature date"), blank=True, null=True) + year = models.IntegerField(_(u"Year"), blank=True, null=True) act_object = models.CharField(_(u"Object"), max_length=200) if settings.COUNTRY == 'fr': ref_sra = models.CharField(u"Référence SRA", max_length=15, blank=True, @@ -501,7 +503,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): _prefix = 'adminact_' class Meta: - ordering = ('index', 'act_type') + ordering = ('year', 'index', 'act_type') verbose_name = _(u"Administrative act") verbose_name_plural = _(u"Administrative acts") permissions = ( @@ -535,13 +537,6 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): return u" ".join(lbl) @property - def year(self): - if not self.signature_date: - return None - return self.signature_date.year - year_lbl = _(u"Year") - - @property def towns(self): if self.associated_file: return self.associated_file.towns.all() @@ -579,9 +574,13 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): return template.publish(self) def save(self, *args, **kwargs): - if not self.act_type.indexed or not self.signature_date: + if not self.signature_date: + return super(AdministrativeAct, self).save(*args, **kwargs) + self.year = self.signature_date.year + + if not self.act_type.indexed: return 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, |