[Plugin] Schedule: Added end as Event attribute
This commit is contained in:
parent
78338027e1
commit
2bbc4898e7
|
@ -255,17 +255,22 @@ def create_event(current_session):
|
||||||
JSON encoded Event object or HTTP-error
|
JSON encoded Event object or HTTP-error
|
||||||
"""
|
"""
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
end = data.get("end", None)
|
||||||
try:
|
try:
|
||||||
start = from_iso_format(data["start"])
|
start = from_iso_format(data["start"])
|
||||||
|
if end is not None:
|
||||||
|
end = from_iso_format(end)
|
||||||
data_type = data["type"]
|
data_type = data["type"]
|
||||||
if isinstance(data_type, dict):
|
if isinstance(data_type, dict):
|
||||||
data_type = data["type"]["id"]
|
data_type = data["type"]["id"]
|
||||||
event_type = event_controller.get_event_type(data_type)
|
event_type = event_controller.get_event_type(data_type)
|
||||||
except (NotFound, KeyError, ValueError):
|
except KeyError:
|
||||||
raise BadRequest("Missing POST parameter")
|
raise BadRequest("Missing POST parameter")
|
||||||
|
except (NotFound, ValueError):
|
||||||
|
raise BadRequest("Invalid parameter")
|
||||||
|
|
||||||
event = event_controller.create_event(
|
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:
|
if "jobs" in data:
|
||||||
for job in data["jobs"]:
|
for job in data["jobs"]:
|
||||||
|
|
|
@ -128,10 +128,10 @@ def delete_event(event_id):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def create_event(event_type, start, jobs=[], description=None):
|
def create_event(event_type, start, end=None, jobs=[], description=None):
|
||||||
try:
|
try:
|
||||||
logger.debug(event_type)
|
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.add(event)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return event
|
return event
|
||||||
|
|
|
@ -78,6 +78,7 @@ class Event(db.Model, ModelSerializeMixin):
|
||||||
|
|
||||||
id: int = db.Column(db.Integer, primary_key=True)
|
id: int = db.Column(db.Integer, primary_key=True)
|
||||||
start: datetime = db.Column(UtcDateTime, nullable=False)
|
start: datetime = db.Column(UtcDateTime, nullable=False)
|
||||||
|
end: datetime = db.Column(UtcDateTime)
|
||||||
description: Optional[str] = db.Column(db.String(255))
|
description: Optional[str] = db.Column(db.String(255))
|
||||||
type: EventType = db.relationship("EventType")
|
type: EventType = db.relationship("EventType")
|
||||||
jobs: [Job] = db.relationship(
|
jobs: [Job] = db.relationship(
|
||||||
|
|
Loading…
Reference in New Issue