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
|
2022-01-24 10:31:48 +01:00
|
|
|
Created on: 24.01.22
|
2022-01-21 17:32:31 +01:00
|
|
|
|
|
|
|
"""
|
2022-01-24 12:17:17 +01:00
|
|
|
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1
|
2022-01-21 17:32:31 +01:00
|
|
|
from compensation.models import Compensation
|
|
|
|
|
|
|
|
|
2022-01-24 10:31:48 +01:00
|
|
|
class CompensationAPISerializerV1(AbstractModelAPISerializerV1):
|
2022-01-21 17:32:31 +01:00
|
|
|
model = Compensation
|
|
|
|
|
2022-01-24 10:31:48 +01:00
|
|
|
def prepare_lookup(self, id, user):
|
2022-01-21 17:32:31 +01:00
|
|
|
self.lookup["id"] = id
|
|
|
|
del self.lookup["users__in"]
|
2022-01-24 10:31:48 +01:00
|
|
|
self.lookup["intervention__users__in"] = [user]
|
2022-01-21 17:32:31 +01:00
|
|
|
|
|
|
|
def intervention_to_json(self, entry):
|
|
|
|
return {
|
|
|
|
"id": entry.pk,
|
|
|
|
"identifier": entry.identifier,
|
|
|
|
"title": entry.title,
|
|
|
|
}
|
|
|
|
|
2022-01-21 18:34:01 +01:00
|
|
|
def extend_properties_data(self, entry):
|
|
|
|
self.properties_data["is_cef"] = entry.is_cef
|
|
|
|
self.properties_data["is_coherence_keeping"] = entry.is_coherence_keeping
|
|
|
|
self.properties_data["intervention"] = self.intervention_to_json(entry.intervention)
|
|
|
|
self.properties_data["before_states"] = self.compensation_state_to_json(entry.before_states.all())
|
|
|
|
self.properties_data["after_states"] = self.compensation_state_to_json(entry.after_states.all())
|
|
|
|
self.properties_data["actions"] = self.compensation_actions_to_json(entry.actions.all())
|
2022-01-24 12:17:17 +01:00
|
|
|
self.properties_data["deadlines"] = self.deadlines_to_json(entry.deadlines.all())
|