From 2bbc4898e76649cb6520327cf578a110efd3a7b0 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 29 Jan 2021 20:07:41 +0100 Subject: [PATCH] [Plugin] Schedule: Added end as Event attribute --- flaschengeist/plugins/schedule/__init__.py | 9 +++++++-- flaschengeist/plugins/schedule/event_controller.py | 4 ++-- flaschengeist/plugins/schedule/models.py | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/flaschengeist/plugins/schedule/__init__.py b/flaschengeist/plugins/schedule/__init__.py index 178b0c1..ebe48ea 100644 --- a/flaschengeist/plugins/schedule/__init__.py +++ b/flaschengeist/plugins/schedule/__init__.py @@ -255,17 +255,22 @@ def create_event(current_session): JSON encoded Event object or HTTP-error """ data = request.get_json() + end = data.get("end", None) try: start = from_iso_format(data["start"]) + if end is not None: + end = from_iso_format(end) data_type = data["type"] if isinstance(data_type, dict): data_type = data["type"]["id"] event_type = event_controller.get_event_type(data_type) - except (NotFound, KeyError, ValueError): + except KeyError: raise BadRequest("Missing POST parameter") + except (NotFound, ValueError): + raise BadRequest("Invalid parameter") event = event_controller.create_event( - start=start, event_type=event_type, description=data["description"] if "description" in data else None + start=start, end=end, event_type=event_type, description=data.get("description", None) ) if "jobs" in data: for job in data["jobs"]: diff --git a/flaschengeist/plugins/schedule/event_controller.py b/flaschengeist/plugins/schedule/event_controller.py index ef60f3c..da72d98 100644 --- a/flaschengeist/plugins/schedule/event_controller.py +++ b/flaschengeist/plugins/schedule/event_controller.py @@ -128,10 +128,10 @@ def delete_event(event_id): db.session.commit() -def create_event(event_type, start, jobs=[], description=None): +def create_event(event_type, start, end=None, jobs=[], description=None): try: logger.debug(event_type) - event = Event(start=start, description=description, type=event_type, jobs=jobs) + event = Event(start=start, end=end, description=description, type=event_type, jobs=jobs) db.session.add(event) db.session.commit() return event diff --git a/flaschengeist/plugins/schedule/models.py b/flaschengeist/plugins/schedule/models.py index 1c7fa27..118c9b9 100644 --- a/flaschengeist/plugins/schedule/models.py +++ b/flaschengeist/plugins/schedule/models.py @@ -78,6 +78,7 @@ class Event(db.Model, ModelSerializeMixin): id: int = db.Column(db.Integer, primary_key=True) start: datetime = db.Column(UtcDateTime, nullable=False) + end: datetime = db.Column(UtcDateTime) description: Optional[str] = db.Column(db.String(255)) type: EventType = db.relationship("EventType") jobs: [Job] = db.relationship(