prevent saving past events
add function to show inactive events
This commit is contained in:
@@ -14,28 +14,38 @@ def get_events():
|
||||
session = Session()
|
||||
start = request.args.get("start")
|
||||
end = request.args.get("end")
|
||||
# geändert: jetzt group_id statt client_uuid
|
||||
group_id = request.args.get("group_id")
|
||||
query = session.query(Event).filter(Event.is_active == True)
|
||||
if start and end:
|
||||
query = query.filter(and_(Event.start < end, Event.end > start))
|
||||
show_inactive = request.args.get(
|
||||
"show_inactive", "0") == "1" # Checkbox-Logik
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
events_query = session.query(Event)
|
||||
if group_id:
|
||||
# geändert: filter auf group_id
|
||||
query = query.filter(Event.group_id == int(group_id))
|
||||
events = query.all()
|
||||
events_query = events_query.filter(Event.group_id == int(group_id))
|
||||
events = events_query.all()
|
||||
|
||||
result = []
|
||||
for e in events:
|
||||
result.append({
|
||||
"Id": str(e.id),
|
||||
"GroupId": e.group_id,
|
||||
"Subject": e.title,
|
||||
"StartTime": e.start.isoformat() if e.start else None,
|
||||
"EndTime": e.end.isoformat() if e.end else None,
|
||||
"IsAllDay": False,
|
||||
"MediaId": e.event_media_id, # <--- Media-ID zurückgeben
|
||||
"SlideshowInterval": e.slideshow_interval,
|
||||
"WebsiteUrl": None, # Optional: für Website-Typ
|
||||
})
|
||||
# Zeitzonen-Korrektur für e.end
|
||||
if e.end and e.end.tzinfo is None:
|
||||
end_dt = e.end.replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
end_dt = e.end
|
||||
|
||||
# Setze is_active auf False, wenn Termin vorbei ist
|
||||
if end_dt and end_dt < now and e.is_active:
|
||||
e.is_active = False
|
||||
session.commit()
|
||||
if show_inactive or e.is_active:
|
||||
result.append({
|
||||
"Id": str(e.id),
|
||||
"GroupId": e.group_id,
|
||||
"Subject": e.title,
|
||||
"StartTime": e.start.isoformat() if e.start else None,
|
||||
"EndTime": e.end.isoformat() if e.end else None,
|
||||
"IsAllDay": False,
|
||||
"MediaId": e.event_media_id,
|
||||
})
|
||||
session.close()
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user