40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
|
"""
|
||
|
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 intervention.models import Intervention
|
||
|
|
||
|
|
||
|
class APIInterventionView(AbstractModelAPIViewV1):
|
||
|
model = Intervention
|
||
|
fields_to_serialize = {
|
||
|
"identifier",
|
||
|
"title",
|
||
|
}
|
||
|
|
||
|
def get(self, request: HttpRequest, identifier):
|
||
|
data = self.fetch_and_serialize("identifier", identifier)
|
||
|
return JsonResponse(data)
|
||
|
|
||
|
def model_to_json(self, entry: Intervention):
|
||
|
entry_json = {
|
||
|
"identifier": entry.identifier,
|
||
|
"title": entry.title,
|
||
|
"responsible": self.responsible_to_json(entry.responsible),
|
||
|
"legal": self.legal_to_json(entry.legal),
|
||
|
"compensations": list(entry.compensations.all().values_list("pk", flat=True)),
|
||
|
"payments": self.payments_to_json(entry.payments.all()),
|
||
|
"deductions": self.deductions_to_json(entry.deductions.all()),
|
||
|
}
|
||
|
geom = entry.geometry.geom.geojson
|
||
|
geo_json = json.loads(geom)
|
||
|
geo_json["properties"] = entry_json
|
||
|
return geo_json
|