diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-08-29 23:38:02 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-08-29 23:38:02 +0200 |
commit | 927755b5e3503af92a7eb38dd592edb1b381c134 (patch) | |
tree | 07efe84a66903ef7c64c34b52d5edc28e5b402c8 | |
parent | 215c8c387088dae24311fa739051b99e9a2f335e (diff) | |
download | Ishtar-927755b5e3503af92a7eb38dd592edb1b381c134.tar.bz2 Ishtar-927755b5e3503af92a7eb38dd592edb1b381c134.zip |
Document generation: manage periods
-rw-r--r-- | archaeological_context_records/models.py | 11 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 4 | ||||
-rw-r--r-- | ishtar_common/models.py | 14 |
3 files changed, 25 insertions, 4 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index d2325082d..3b236346d 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -90,6 +90,17 @@ class Dating(models.Model): return str(self.period) return "%s (%s-%s)" % (self.period, start_date, end_date) + 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 + } + HISTORY_ATTR = ["period", "start_date", "end_date", "dating_type", "quality", "precise_dating"] diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 0e93723c9..bd1db0700 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1718,6 +1718,10 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, ] return values + def get_values_for_datings(self, prefix=''): + return [dating.get_values(prefix=prefix) + for dating in self.datings.all()] + @property def reference(self): bf = self.get_first_base_find() diff --git a/ishtar_common/models.py b/ishtar_common/models.py index dbbebae84..176559934 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -126,6 +126,8 @@ class ValueGetter(object): GET_VALUES_EXCLUDE_FIELDS = [ 'search_vector', 'id', 'multi_polygon', 'point_2d', 'point', 'history_m2m'] + GET_VALUES_ = [ + 'preservation_to_considers', 'alterations', 'alteration_causes'] GET_VALUES_EXTRA_TYPES = [ 'preservation_to_considers', 'alterations', 'alteration_causes'] @@ -153,11 +155,15 @@ class ValueGetter(object): if not hasattr(self, field_name) or \ field_name in self.GET_VALUES_EXCLUDE_FIELDS: continue - value = getattr(self, field_name) - if hasattr(value, 'get_values'): - values.update(value.get_values(prefix + field_name + '_')) + if hasattr(self, "get_values_for_" + field_name): + values[prefix + field_name] = getattr( + self, "get_values_for_" + field_name)() else: - values[prefix + field_name] = value + value = getattr(self, field_name) + if hasattr(value, 'get_values'): + values.update(value.get_values(prefix + field_name + '_')) + else: + values[prefix + field_name] = value values.update(self._get_values_documents(prefix=prefix)) for extra_field in self.GET_VALUES_EXTRA: values[prefix + extra_field] = getattr(self, extra_field) or '' |