feat(events): reliable holiday skipping for recurrences + UI badge; clean logs

Backend: generate EventException on create/update when skip_holidays or recurrence changes; emit RecurrenceException (EXDATE) with exact occurrence start time (UTC)
API: return master events with RecurrenceRule + RecurrenceException
Frontend: map RecurrenceException → recurrenceException; ensure SkipHolidays instances never render on holidays; place TentTree icon (black) next to main event icon via template
Docs: update README and Copilot instructions for recurrence/holiday behavior
Cleanup: remove dataSource and debug console logs
This commit is contained in:
RobbStarkAustria
2025-10-12 12:00:43 +00:00
parent 7ab4ea14c4
commit 773628c324
15 changed files with 698 additions and 122 deletions

View File

@@ -4,7 +4,9 @@ import os
from datetime import datetime
from sqlalchemy.orm import sessionmaker, joinedload
from sqlalchemy import create_engine
from models.models import Event, EventMedia
from models.models import Event, EventMedia, EventException
from dateutil.rrule import rrulestr
from datetime import timezone
load_dotenv('/workspace/.env')
@@ -34,8 +36,37 @@ def get_active_events(start: datetime, end: datetime, group_id: int = None):
formatted_events = []
for event in events:
formatted_event = format_event_with_media(event)
formatted_events.append(formatted_event)
# If event has RRULE, expand into instances within [start, end]
if event.recurrence_rule:
try:
r = rrulestr(event.recurrence_rule, dtstart=event.start)
# iterate occurrences within range
occ_starts = r.between(start, end, inc=True)
duration = (event.end - event.start) if (event.end and event.start) else None
for occ_start in occ_starts:
occ_end = (occ_start + duration) if duration else occ_start
# Apply exceptions
exc = session.query(EventException).filter(
EventException.event_id == event.id,
EventException.exception_date == occ_start.date()
).first()
if exc:
if exc.is_skipped:
continue
if exc.override_start:
occ_start = exc.override_start
if exc.override_end:
occ_end = exc.override_end
inst = format_event_with_media(event)
inst["start"] = occ_start.isoformat()
inst["end"] = occ_end.isoformat()
inst["occurrence_of_id"] = event.id
formatted_events.append(inst)
except Exception:
# On parse error, fall back to single event formatting
formatted_events.append(format_event_with_media(event))
else:
formatted_events.append(format_event_with_media(event))
return formatted_events
finally:
@@ -50,6 +81,9 @@ def format_event_with_media(event):
"start": str(event.start),
"end": str(event.end),
"group_id": event.group_id,
# Carry recurrence metadata for consumers if needed
"recurrence_rule": getattr(event, "recurrence_rule", None),
"recurrence_end": (event.recurrence_end.isoformat() if getattr(event, "recurrence_end", None) else None),
}
# Now you can directly access event.event_media

View File

@@ -2,3 +2,4 @@ paho-mqtt
sqlalchemy
pymysql
python-dotenv
python-dateutil