#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:
@@ -12,7 +12,8 @@ from django.db.models import QuerySet
|
||||
|
||||
from api.utils.serializer.serializer import AbstractModelAPISerializer
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID, CODELIST_PROCESS_TYPE_ID, \
|
||||
CODELIST_LAW_ID, CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID
|
||||
from compensation.models import CompensationAction, UnitChoices, CompensationState
|
||||
from intervention.models import Responsibility, Legal
|
||||
from konova.models import Deadline, DeadlineType
|
||||
@@ -154,6 +155,31 @@ class ResponsibilityAPISerializerV1Mixin:
|
||||
"handler": responsible.handler,
|
||||
}
|
||||
|
||||
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.get("registration_office", None),
|
||||
CODELIST_REGISTRATION_OFFICE_ID
|
||||
)
|
||||
obj.responsible.registration_file_number = responsibility_data.get("registration_file_number", None)
|
||||
obj.responsible.conservation_office = self.konova_code_from_json(
|
||||
responsibility_data.get("conservation_office", None),
|
||||
CODELIST_CONSERVATION_OFFICE_ID,
|
||||
)
|
||||
obj.responsible.conservation_file_number = responsibility_data.get("conservation_file_number", None)
|
||||
obj.responsible.handler = responsibility_data.get("handler", None)
|
||||
return obj
|
||||
|
||||
|
||||
class LegalAPISerializerV1Mixin:
|
||||
class Meta:
|
||||
@@ -175,6 +201,28 @@ class LegalAPISerializerV1Mixin:
|
||||
"laws": [self.konova_code_to_json(law) for law in legal.laws.all()],
|
||||
}
|
||||
|
||||
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.get("registration_date", None)
|
||||
obj.legal.binding_date = legal_data.get("binding_date", None)
|
||||
obj.legal.process_type = self.konova_code_from_json(
|
||||
legal_data.get("process_type", None),
|
||||
CODELIST_PROCESS_TYPE_ID,
|
||||
)
|
||||
laws = [self.konova_code_from_json(law, CODELIST_LAW_ID) for law in legal_data.get("laws", [])]
|
||||
obj.legal.laws.set(laws)
|
||||
return obj
|
||||
|
||||
|
||||
class AbstractCompensationAPISerializerV1Mixin:
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user