[Plugin] schedule: Allow creating JobSlots from POST
This commit is contained in:
parent
5a8a4aa23d
commit
d8100b129e
|
@ -213,14 +213,19 @@ def get_events(current_session, year=datetime.now().year, month=datetime.now().m
|
||||||
raise BadRequest("Invalid date given")
|
raise BadRequest("Invalid date given")
|
||||||
|
|
||||||
|
|
||||||
def _event_slot_from_data(data):
|
def _add_event_slot(event, data):
|
||||||
|
end = None
|
||||||
try:
|
try:
|
||||||
start = from_iso_format(data["start"])
|
start = from_iso_format(data["start"])
|
||||||
end = from_iso_format(data["end"]) if "end" in data else None
|
except (KeyError, ValueError):
|
||||||
# jobs = ...
|
|
||||||
except (NotFound, KeyError, ValueError):
|
|
||||||
raise BadRequest("Missing POST parameter")
|
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"])
|
@schedule_bp.route("/events", methods=["POST"])
|
||||||
|
@ -251,7 +256,7 @@ def create_event(current_session):
|
||||||
)
|
)
|
||||||
if "slots" in data:
|
if "slots" in data:
|
||||||
for slot in data["slots"]:
|
for slot in data["slots"]:
|
||||||
event_controller.add_event_slot(event, **_event_slot_from_data(slot))
|
_add_event_slot(event, slot)
|
||||||
return jsonify(event)
|
return jsonify(event)
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,7 +328,7 @@ def add_event_slot(event_id, current_session):
|
||||||
if not data:
|
if not data:
|
||||||
raise BadRequest("Missing POST parameters")
|
raise BadRequest("Missing POST parameters")
|
||||||
|
|
||||||
event_controller.add_event_slot(event, **_event_slot_from_data(data))
|
_add_event_slot(event, data)
|
||||||
return jsonify(event)
|
return jsonify(event)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,7 @@ def add_event_slot(event, start, end=None):
|
||||||
raise BadRequest("Start before event start")
|
raise BadRequest("Start before event start")
|
||||||
db.session.add(event_slot)
|
db.session.add(event_slot)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
return event_slot
|
||||||
|
|
||||||
|
|
||||||
def remove_event_slot(event, slot_id):
|
def remove_event_slot(event, slot_id):
|
||||||
|
|
Loading…
Reference in New Issue