diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-09-28 17:34:26 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-09-28 17:34:26 +0200 |
commit | 0a46d296dfa8c02506b436106ffae5869a905b86 (patch) | |
tree | 6858e73faff2888b4fe6e8febdc8c7f285fe4ae8 /archaeological_operations/models.py | |
parent | 0f62b35fc726e773f24068789eeede745f8cca75 (diff) | |
download | Ishtar-0a46d296dfa8c02506b436106ffae5869a905b86.tar.bz2 Ishtar-0a46d296dfa8c02506b436106ffae5869a905b86.zip |
Parcel list for document templates
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 0a83dbdfc..7e4bd73b6 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -246,6 +246,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem): if self.towns.count(): values[prefix+'towns'] = u", ".join([town.name for town in self.towns.all().order_by('name')]) + values[prefix+'parcellist'] = self.render_parcels() return values @property @@ -305,6 +306,9 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem): def grouped_parcels(self): return Parcel.grouped_parcels(list(self.parcels.all())) + def render_parcels(self): + return Parcel.render_parcels(list(self.parcels.all())) + def context_record_docs_q(self): from archaeological_context_records.models import ContextRecordSource return ContextRecordSource.objects.filter( @@ -660,8 +664,8 @@ class Parcel(LightHistorizedItem): def __unicode__(self): return self.short_label - @staticmethod - def grouped_parcels(parcels): + @classmethod + def grouped_parcels(cls, parcels): sortkeyfn = lambda s:(getattr(s, 'town_id'), getattr(s, 'section'), getattr(s, 'year')) parcels = sorted(parcels, key=sortkeyfn) @@ -678,6 +682,28 @@ class Parcel(LightHistorizedItem): for nb in grouped[-1].parcel_numbers] return grouped + + @classmethod + def render_parcels(cls, parcels): + parcels = cls.grouped_parcels(parcels) + res = '' + c_town, c_section, c_year = '', '', '' + for idx, parcels in enumerate(parcels): + if c_town != unicode(parcels.town): + c_town = unicode(parcels.town) + c_section, c_year = '', '' + if idx: + res += " ; " + res += unicode(parcels.town) + u' : ' + if c_section: + res += u" / " + c_section = parcels.section + res += parcels.section + u' ' + res += u", ".join(parcels.parcel_numbers) + if parcels.year: + res += " (%s)" % unicode(parcels.year) + return res + def long_label(self): items = [unicode(self.operation or self.associated_file)] items += [unicode(item) for item in [self.section, self.parcel_number] |