[Plugin] Schedule: Added end as Event attribute

This commit is contained in:
Ferdinand Thiessen 2021-01-29 20:07:41 +01:00
parent 78338027e1
commit 2bbc4898e7
3 changed files with 10 additions and 4 deletions

View File

@ -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"]:

View File

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

View File

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