mpeltriaux
59c5caf8ac
* splits large AbstractModelAPISerializer into different reusable Mixins to increase reusability of code for similar models
30 lines
1.4 KiB
Python
30 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, AbstractCompensationAPISerializerV1Mixin, \
|
|
ResponsibilityAPISerializerV1Mixin
|
|
from ema.models import Ema
|
|
from intervention.models import Responsibility
|
|
|
|
|
|
class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin):
|
|
model = Ema
|
|
|
|
def responsible_to_json(self, responsible: Responsibility):
|
|
return {
|
|
"conservation_office": self.konova_code_to_json(responsible.conservation_office),
|
|
"conservation_file_number": responsible.conservation_file_number,
|
|
"handler": responsible.handler,
|
|
}
|
|
|
|
def extend_properties_data(self, entry):
|
|
self.properties_data["responsible"] = self.responsible_to_json(entry.responsible)
|
|
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())
|