[Plugin] schedule: Fixed set JobType by JSON.

This commit is contained in:
Ferdinand Thiessen 2021-01-26 22:25:30 +01:00
parent a8c7ddae3d
commit a4a9d05a31
2 changed files with 8 additions and 3 deletions

View File

@ -232,7 +232,10 @@ def _add_job(event, data):
if "required_services" not in data:
raise BadRequest
job_type = event_controller.get_job_type(data["type"])
job_type = data["type"]
if isinstance(job_type, dict):
job_type = data["type"]["id"]
job_type = event_controller.get_job_type(job_type)
event_controller.add_job(event, job_type, data["required_services"], start, end, comment=data.get("comment"))
@ -261,7 +264,6 @@ def create_event(current_session):
except (NotFound, KeyError, ValueError):
raise BadRequest("Missing POST parameter")
data = request.get_json()
event = event_controller.create_event(
start=start, event_type=event_type, description=data["description"] if "description" in data else None
)

View File

@ -19,8 +19,11 @@ def get_event_type(identifier):
if isinstance(identifier, int):
et = EventType.query.get(identifier)
else:
elif isinstance(identifier, str):
et = EventType.query.filter(EventType.name == identifier).one_or_none()
else:
logger.debug("Invalid identifier type for EventType")
raise BadRequest
if not et:
raise NotFound
return et