[Plugin] schedule: Allow creating JobSlots from POST

This commit is contained in:
Ferdinand Thiessen 2020-11-02 16:30:10 +01:00
parent 5a8a4aa23d
commit d8100b129e
2 changed files with 13 additions and 7 deletions

View File

@ -213,14 +213,19 @@ def get_events(current_session, year=datetime.now().year, month=datetime.now().m
raise BadRequest("Invalid date given")
def _event_slot_from_data(data):
def _add_event_slot(event, data):
end = None
try:
start = from_iso_format(data["start"])
end = from_iso_format(data["end"]) if "end" in data else None
# jobs = ...
except (NotFound, KeyError, ValueError):
except (KeyError, ValueError):
raise BadRequest("Missing POST parameter")
return {"start": start, "end": end}
if "end" in data:
end = from_iso_format(data["end"])
event_slot = event_controller.add_event_slot(event, start, end)
if "jobs" in data:
for job_data in data["jobs"]:
job_type = event_controller.get_job_type(job_data["type"])
event_controller.add_job_slot(event_slot, job_type, job_data["required_jobs"])
@schedule_bp.route("/events", methods=["POST"])
@ -251,7 +256,7 @@ def create_event(current_session):
)
if "slots" in data:
for slot in data["slots"]:
event_controller.add_event_slot(event, **_event_slot_from_data(slot))
_add_event_slot(event, slot)
return jsonify(event)
@ -323,7 +328,7 @@ def add_event_slot(event_id, current_session):
if not data:
raise BadRequest("Missing POST parameters")
event_controller.add_event_slot(event, **_event_slot_from_data(data))
_add_event_slot(event, data)
return jsonify(event)

View File

@ -144,6 +144,7 @@ def add_event_slot(event, start, end=None):
raise BadRequest("Start before event start")
db.session.add(event_slot)
db.session.commit()
return event_slot
def remove_event_slot(event, slot_id):