Add EventSeries (club-scoped): an RFC-5545 rrule + dtstart + duration and a template (kind/title/location/opponent + audience M2M). Concrete Event rows are materialised occurrences carrying a series FK plus detached/cancelled flags; the series tracks excluded_dates (EXDATEs) and a generated_until horizon watermark. Recurrence service: - occurrence_datetimes expands the rrule (via python-dateutil) up to a horizon, minus EXDATEs. - generate_occurrences materialises missing rows, copies the template + audience (so attendance syncs through the existing signals), and is idempotent. - cancel_occurrence adds an EXDATE and deletes (or soft-cancels) one occurrence so it isn't regenerated; detach_occurrence marks an occurrence as independently edited; propagate_series re-applies the template to non-detached future occurrences. - extend_event_series management command rolls the horizon forward. Register EventSeries in the admin and surface series/detached/cancelled on the Event admin. Add python-dateutil. Full suite at 100% coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
21 lines
732 B
Python
21 lines
732 B
Python
from django.core.management.base import BaseCommand
|
|
|
|
from events.models import EventSeries
|
|
from events.services import generate_occurrences, horizon
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Materialise recurring event occurrences up to the rolling horizon."
|
|
|
|
def handle(self, *args, **options):
|
|
until = horizon()
|
|
total = 0
|
|
|
|
for series in EventSeries.objects.all():
|
|
created = generate_occurrences(series, until)
|
|
total += len(created)
|
|
if created:
|
|
self.stdout.write(f"{series}: generated {len(created)} occurrence(s).")
|
|
|
|
self.stdout.write(self.style.SUCCESS(f"Done. Generated {total} occurrence(s) across {EventSeries.objects.count()} series."))
|