From 7185d81691ede9520cecdd2a2e8dcac372aaac6c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 12 Jul 2019 17:47:56 +0200 Subject: Base public serializer --- archaeological_operations/models.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'archaeological_operations') diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index a6e55a59e..336a9ca74 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -342,6 +342,24 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem, def short_class_name(self): return _("SITE") + def public_representation(self): + dct = super(ArchaeologicalSite, self).public_representation() + dct.update({ + "reference": self.reference, + "name": self.name, + "materials": [str(p) for p in self.periods.all()], + "remains": [str(r) for r in self.remains.all()], + "towns": [t.label_with_areas() for t in self.towns.all()], + "comment": self.comment, + "locality": self.locality_ngi or self.locality_cadastral, + }) + profile = get_current_profile() + if profile.underwater(): + dct["shipwreck-name"] = self.shipwreck_name + dct["sinking-date"] = self.sinking_date + dct["discovery-area"] = self.discovery_area + return dct + @property def finds(self): from archaeological_finds.models import Find @@ -1068,6 +1086,21 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, ] return values + def public_representation(self): + dct = super(Operation, self).public_representation() + dct.update({ + "year": self.year, + "common-name": self.common_name, + "operation-type": self.operation_type and str(self.operation_type), + "remains": [str(r) for r in self.remains.all()], + "periods": [str(p) for p in self.periods.all()], + "excavation-start-date": self.start_date, + "excavation-end-date": self.excavation_end_date, + "address": self.address, + "comment": self.comment, + }) + return dct + @classmethod def _get_department_code(cls, value): if not settings.ISHTAR_DPTS: -- cgit v1.2.3