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

34 lines
1.4 KiB
Python

"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 24.01.22
"""
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1
from compensation.models import Compensation
class CompensationAPISerializerV1(AbstractModelAPISerializerV1):
model = Compensation
def prepare_lookup(self, id, user):
self.lookup["id"] = id
del self.lookup["users__in"]
self.lookup["intervention__users__in"] = [user]
def intervention_to_json(self, entry):
return {
"id": entry.pk,
"identifier": entry.identifier,
"title": entry.title,
}
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())
self.properties_data["deadlines"] = self.deadlines_to_json(entry.deadlines.all())