""" 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 JsonResponse, HttpRequest from api.views.v1.ecoaccount import APIEcoAccountViewV1 from ema.models import Ema class APIEmaViewV1(APIEcoAccountViewV1): model = Ema def get(self, request: HttpRequest, id): self.lookup["id"] = id self.lookup["users__in"] = [self.user] data = self.fetch_and_serialize() return JsonResponse(data) def model_to_json(self, entry): entry_json = { "identifier": entry.identifier, "title": entry.title, "responsible": self.responsible_to_json(entry.responsible), "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": self.modified_on_to_json(entry), "created_on": self.created_on_to_json(entry), } geom = entry.geometry.geom.geojson geo_json = json.loads(geom) geo_json["properties"] = entry_json return geo_json