""" Author: Michel Peltriaux Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany Contact: michel.peltriaux@sgdnord.rlp.de Created on: 21.01.22 """ import json from django.http import HttpRequest, JsonResponse from api.views.v1.general import AbstractModelAPIViewV1 from compensation.models import Compensation class APICompensationViewV1(AbstractModelAPIViewV1): model = Compensation def get(self, request: HttpRequest, id): self.lookup["id"] = id del self.lookup["users__in"] self.lookup["intervention__users__in"] = [self.user] data = self.fetch_and_serialize() return JsonResponse(data) def intervention_to_json(self, entry): return { "id": entry.pk, "identifier": entry.identifier, "title": entry.title, } def model_to_json(self, entry): modified_on = entry.modified or entry.created modified_on = modified_on.timestamp entry_json = { "identifier": entry.identifier, "title": entry.title, "is_cef": entry.is_cef, "is_coherence_keeping": entry.is_coherence_keeping, "intervention": self.intervention_to_json(entry.intervention), "before_states": self.compensation_state_to_json(entry.before_states.all()), "after_states": self.compensation_state_to_json(entry.after_states.all()), "actions": self.compensation_actions_to_json(entry.actions.all()), "deadlines": self.deadlines_to_json(entry.deadlines.all()), "modified_on": modified_on, "created_on": entry.created.timestamp, } geom = entry.geometry.geom.geojson geo_json = json.loads(geom) geo_json["properties"] = entry_json return geo_json