[events] Respect backup assignment

This commit is contained in:
Ferdinand Thiessen 2021-11-21 17:52:06 +01:00
parent d75574e078
commit 51a3a8dfc8
1 changed files with 9 additions and 6 deletions

View File

@ -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()