#31 API PUT/POST Ema

* adds support for PUT and POST of Ema
* moves set_responsibility() and set_legal() from Intervention API Serializer into proper Mixins where they belong to
This commit is contained in:
2022-01-24 16:43:37 +01:00
parent f461a8e38d
commit 89fb867ab2
3 changed files with 154 additions and 50 deletions

View File

@@ -10,8 +10,6 @@ from django.db.models import QuerySet
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, \
ResponsibilityAPISerializerV1Mixin, LegalAPISerializerV1Mixin, DeductableAPISerializerV1Mixin
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID, \
CODELIST_PROCESS_TYPE_ID, CODELIST_LAW_ID
from compensation.models import Payment
from intervention.models import Intervention, Responsibility, Legal
from konova.models import Geometry
@@ -80,53 +78,6 @@ class InterventionAPISerializerV1(AbstractModelAPISerializerV1,
obj.responsible = resp
return obj
def set_legal(self, obj, legal_data):
""" Sets the legal data contents to the provided legal_data dict
Args:
obj (Intervention): The intervention object
legal_data (dict): The new data
Returns:
obj
"""
if legal_data is None:
return obj
obj.legal.registration_date = legal_data["registration_date"]
obj.legal.binding_date = legal_data["binding_date"]
obj.legal.process_type = self.konova_code_from_json(
legal_data["process_type"],
CODELIST_PROCESS_TYPE_ID,
)
laws = [self.konova_code_from_json(law, CODELIST_LAW_ID) for law in legal_data["laws"]]
obj.legal.laws.set(laws)
return obj
def set_responsibility(self, obj, responsibility_data: dict):
""" Sets the responsible data contents to the provided responsibility_data dict
Args:
obj (Intervention): The intervention object
responsibility_data (dict): The new data
Returns:
obj
"""
if responsibility_data is None:
return obj
obj.responsible.registration_office = self.konova_code_from_json(
responsibility_data["registration_office"],
CODELIST_REGISTRATION_OFFICE_ID
)
obj.responsible.registration_file_number = responsibility_data["registration_file_number"]
obj.responsible.conservation_office = self.konova_code_from_json(
responsibility_data["conservation_office"],
CODELIST_CONSERVATION_OFFICE_ID,
)
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
obj.responsible.handler = responsibility_data["handler"]
return obj
def set_payments(self, obj, payment_data):
""" Sets the linked Payment data according to the given payment_data