31_API #90

Merged
mpeltriaux merged 36 commits from 31_API into master 2022-01-28 16:38:11 +01:00
2 changed files with 43 additions and 0 deletions
Showing only changes of commit 870cc96a1a - Show all commits

View File

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

41
api/views/v1/ema.py Normal file
View File

@ -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