#31 API basic implementation Ema fetch

* adds API support for fetching EMA
pull/90/head
mpeltriaux 3 years ago
parent 4f6964b04a
commit 870cc96a1a

@ -9,6 +9,7 @@ from django.urls import path
from api.views.v1.compensation import APICompensationViewV1
from api.views.v1.ecoaccount import APIEcoAccountViewV1
from api.views.v1.ema import APIEmaViewV1
from api.views.v1.intervention import APIInterventionViewV1
app_name = "v1"
@ -16,4 +17,5 @@ urlpatterns = [
path("intervention/<id>", APIInterventionViewV1.as_view(), name="intervention"),
path("compensation/<id>", APICompensationViewV1.as_view(), name="compensation"),
path("ecoaccount/<id>", APIEcoAccountViewV1.as_view(), name="ecoaccount"),
path("ema/<id>", APIEmaViewV1.as_view(), name="ema"),
]

@ -0,0 +1,41 @@
"""
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
Loading…
Cancel
Save