diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-11-06 12:05:11 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-11-06 12:06:43 +0100 |
commit | afa3761a57ac3d2fe2cabe50a4956a188119bddf (patch) | |
tree | 02f9abfc37c78c31ed53185d10ac28e24f551918 /archaeological_context_records | |
parent | 72b0e6ca45a7296f6288bf994ff3da86c85bad32 (diff) | |
download | Ishtar-afa3761a57ac3d2fe2cabe50a4956a188119bddf.tar.bz2 Ishtar-afa3761a57ac3d2fe2cabe50a4956a188119bddf.zip |
Label generation: optimize template evaluation
Diffstat (limited to 'archaeological_context_records')
-rw-r--r-- | archaeological_context_records/models.py | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 8e69ac505..8d69fba4b 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -133,16 +133,23 @@ class Dating(models.Model): def natural_key(self): return self.uuid, - def get_values(self, prefix='', no_values=False): - return { - prefix + "period": str(self.period), - prefix + "start_date": self.start_date or '', - prefix + "end_date": self.end_date or "", - prefix + "dating_type": - str(self.dating_type) if self.dating_type else "", - prefix + "quality": str(self.quality) if self.quality else "", - prefix + "precise_dating": self.precise_dating - } + def get_values(self, prefix='', no_values=False, filtr=None, **kwargs): + values = {} + if not filtr or prefix + "period" in filtr: + values[prefix + "period"] = str(self.period) + if not filtr or prefix + "start_date" in filtr: + values[prefix + "start_date"] = self.start_date or '' + if not filtr or prefix + "end_date" in filtr: + values[prefix + "end_date"] = self.end_date or '' + if not filtr or prefix + "dating_type" in filtr: + values[prefix + "dating_type"] = \ + str(self.dating_type) if self.dating_type else "" + if not filtr or prefix + "quality" in filtr: + values[prefix + "quality"] = \ + str(self.quality) if self.quality else "" + if not filtr or prefix + "precise_dating" in filtr: + values[prefix + "precise_dating"] = self.precise_dating + return values HISTORY_ATTR = ["period", "start_date", "end_date", "dating_type", "quality", "precise_dating"] @@ -652,15 +659,20 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, }) return dct - def get_values(self, prefix='', no_values=False, no_base_finds=True): - values = super(ContextRecord, self).get_values(prefix=prefix, - no_values=no_values) + def get_values(self, prefix='', no_values=False, filtr=None, **kwargs): + no_base_finds = True + if "no_base_finds" in kwargs: + no_base_finds = kwargs["no_base_finds"] + values = super(ContextRecord, self).get_values( + prefix=prefix, no_values=no_values, filtr=filtr, **kwargs) if prefix and no_base_finds: return values - values[prefix + 'base_finds'] = [ - bf.get_values(prefix=prefix, no_values=True) - for bf in self.base_finds.distinct().all() - ] + + if not filtr or prefix + 'base_finds' in filtr: + values[prefix + 'base_finds'] = [ + bf.get_values( + prefix=prefix, no_values=True, filtr=None, **kwargs) + for bf in self.base_finds.distinct().all()] return values def get_town_centroid(self): |