2022-01-21 15:26:08 +01:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 21.01.22
|
|
|
|
|
|
|
|
"""
|
|
|
|
import json
|
|
|
|
|
2022-01-21 16:29:59 +01:00
|
|
|
from django.db.models import QuerySet
|
2022-01-21 15:26:08 +01:00
|
|
|
from django.http import HttpRequest, JsonResponse
|
|
|
|
|
|
|
|
from api.views.v1.general import AbstractModelAPIViewV1
|
|
|
|
from intervention.models import Intervention
|
|
|
|
|
|
|
|
|
2022-01-21 16:15:16 +01:00
|
|
|
class APIInterventionViewV1(AbstractModelAPIViewV1):
|
2022-01-21 15:26:08 +01:00
|
|
|
model = Intervention
|
|
|
|
|
2022-01-21 16:29:59 +01:00
|
|
|
def get(self, request: HttpRequest, id):
|
2022-01-21 17:32:31 +01:00
|
|
|
self.lookup["id"] = id
|
|
|
|
self.lookup["users__in"] = [self.user]
|
|
|
|
|
|
|
|
data = self.fetch_and_serialize()
|
2022-01-21 15:26:08 +01:00
|
|
|
return JsonResponse(data)
|
|
|
|
|
2022-01-21 16:29:59 +01:00
|
|
|
def compensations_to_json(self, qs: QuerySet):
|
|
|
|
return list(
|
|
|
|
qs.values(
|
|
|
|
"id", "identifier", "title"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-01-21 15:26:08 +01:00
|
|
|
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),
|
2022-01-21 16:29:59 +01:00
|
|
|
"compensations": self.compensations_to_json(entry.compensations.all()),
|
2022-01-21 15:26:08 +01:00
|
|
|
"payments": self.payments_to_json(entry.payments.all()),
|
|
|
|
"deductions": self.deductions_to_json(entry.deductions.all()),
|
2022-01-21 17:44:58 +01:00
|
|
|
"modified_on": self.modified_on_to_json(entry),
|
|
|
|
"created_on": self.created_on_to_json(entry),
|
2022-01-21 15:26:08 +01:00
|
|
|
}
|
|
|
|
geom = entry.geometry.geom.geojson
|
|
|
|
geo_json = json.loads(geom)
|
|
|
|
geo_json["properties"] = entry_json
|
|
|
|
return geo_json
|