2022-01-21 17:32:31 +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
|
|
|
|
|
|
|
|
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()),
|
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 17:32:31 +01:00
|
|
|
}
|
|
|
|
geom = entry.geometry.geom.geojson
|
|
|
|
geo_json = json.loads(geom)
|
|
|
|
geo_json["properties"] = entry_json
|
|
|
|
return geo_json
|