#31 API POST Compensation
* adds documentations * adds check for valid deadline type
This commit is contained in:
parent
79acf63dbf
commit
02e72e015f
@ -11,7 +11,7 @@ from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID
|
||||
from compensation.models import Compensation, CompensationAction, CompensationState, UnitChoices
|
||||
from intervention.models import Intervention
|
||||
from konova.models import Geometry, Deadline
|
||||
from konova.models import Geometry, Deadline, DeadlineType
|
||||
from konova.tasks import celery_update_parcels
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
@ -67,7 +67,7 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1):
|
||||
return obj
|
||||
|
||||
def set_intervention(self, obj, intervention_id, user):
|
||||
""" Sets the linked intervention according to the given id
|
||||
""" Sets the linked compensation according to the given id
|
||||
|
||||
Fails if no such intervention found or user has no shared access
|
||||
|
||||
@ -89,12 +89,25 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1):
|
||||
return obj
|
||||
|
||||
def set_deadlines(self, obj, deadline_data):
|
||||
""" Sets the linked deadline data according to the given deadline_data
|
||||
|
||||
|
||||
Args:
|
||||
obj (Compensation): The Compensation object
|
||||
deadline_data (dict): The posted deadline_data
|
||||
|
||||
Returns:
|
||||
obj (Compensation)
|
||||
"""
|
||||
found_deadlines = []
|
||||
for entry in deadline_data:
|
||||
deadline_type = entry["type"]
|
||||
date = entry["date"]
|
||||
comment = entry["comment"]
|
||||
|
||||
if deadline_type not in DeadlineType:
|
||||
raise ValueError(f"Invalid deadline type. Choices are {DeadlineType.values}")
|
||||
|
||||
pre_existing_deadlines = obj.deadlines.filter(
|
||||
type=deadline_type,
|
||||
date=date,
|
||||
@ -115,6 +128,17 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1):
|
||||
return obj
|
||||
|
||||
def set_compensation_states(self, obj, states_data, states_manager):
|
||||
""" Sets the linked compensation state data according to the given states_data
|
||||
|
||||
|
||||
Args:
|
||||
obj (Compensation): The Compensation object
|
||||
states_data (dict): The posted states_data
|
||||
states_manager (Manager): The before_states or after_states manager
|
||||
|
||||
Returns:
|
||||
obj (Compensation)
|
||||
"""
|
||||
found_states = []
|
||||
for entry in states_data:
|
||||
biotope_type = entry["biotope"]
|
||||
@ -139,6 +163,16 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1):
|
||||
return obj
|
||||
|
||||
def set_compensation_actions(self, obj, actions_data):
|
||||
""" Sets the linked compensation action data according to the given actions_data
|
||||
|
||||
|
||||
Args:
|
||||
obj (Compensation): The Compensation object
|
||||
actions_data (dict): The posted actions_data
|
||||
|
||||
Returns:
|
||||
obj (Compensation)
|
||||
"""
|
||||
found_actions = []
|
||||
for entry in actions_data:
|
||||
action = entry["action"]
|
||||
|
Loading…
Reference in New Issue
Block a user