From 51a3a8dfc84da3f25b31afdf53fa8a1739778546 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 21 Nov 2021 17:52:06 +0100 Subject: [PATCH] [events] Respect backup assignment --- flaschengeist/plugins/events/event_controller.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/flaschengeist/plugins/events/event_controller.py b/flaschengeist/plugins/events/event_controller.py index b5f7410..6a3f9f2 100644 --- a/flaschengeist/plugins/events/event_controller.py +++ b/flaschengeist/plugins/events/event_controller.py @@ -195,11 +195,14 @@ def create_event(event_type, start, end=None, jobs=[], is_template=None, name=No raise BadRequest -def get_job(job_slot_id, event_id): - js = Job.query.filter(Job.id == job_slot_id).filter(Job.event_id_ == event_id).one_or_none() - if js is None: +def get_job(job_id, event_id=None) -> Job: + query = Job.query.filter(Job.id == job_id) + if event_id is not None: + query = query.filter(Job.event_id_ == event_id) + job = query.one_or_none() + if job is None: raise NotFound - return js + return job def add_job(event, job_type, required_services, start, end=None, comment=None): @@ -233,13 +236,13 @@ def delete_job(job: Job): db.session.commit() -def assign_job(job: Job, user, value): +def assign_job(job: Job, user, value, is_backup=False): assert value > 0 service = Service.query.get((job.id, user.id_)) if service: service.value = value else: - service = Service(user_=user, value=value, job_=job) + service = Service(user_=user, value=value, is_backup=is_backup, job_=job) db.session.add(service) db.session.commit()