You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
konova/api/views/v1/intervention.py

49 lines
1.5 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.db.models import QuerySet
from django.http import HttpRequest, JsonResponse
from api.views.v1.general import AbstractModelAPIViewV1
from intervention.models import Intervention
class APIInterventionViewV1(AbstractModelAPIViewV1):
model = Intervention
def get(self, request: HttpRequest, id):
_filter = {
"id": id,
"users__in": [self.user],
"deleted__isnull": True,
}
data = self.fetch_and_serialize(_filter)
return JsonResponse(data)
def compensations_to_json(self, qs: QuerySet):
return list(
qs.values(
"id", "identifier", "title"
)
)
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": self.compensations_to_json(entry.compensations.all()),
"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