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/compensation.py

51 lines
1.7 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 compensation.models import Compensation
class APICompensationViewV1(AbstractModelAPIViewV1):
model = Compensation
def get(self, request: HttpRequest, id):
self.lookup["id"] = id
del self.lookup["users__in"]
self.lookup["intervention__users__in"] = [self.user]
data = self.fetch_and_serialize()
return JsonResponse(data)
def intervention_to_json(self, entry):
return {
"id": entry.pk,
"identifier": entry.identifier,
"title": entry.title,
}
def model_to_json(self, entry):
entry_json = {
"identifier": entry.identifier,
"title": entry.title,
"is_cef": entry.is_cef,
"is_coherence_keeping": entry.is_coherence_keeping,
"intervention": self.intervention_to_json(entry.intervention),
"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