#31 API POST Intervention
* adds support for proper POST of intervention * makes /<id> optional (required for Post)
This commit is contained in:
34
api/utils/serializer/v1/compensation.py
Normal file
34
api/utils/serializer/v1/compensation.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
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())
|
||||
Reference in New Issue
Block a user