From b08c3895cea42ff027e3d6bf2585ab9cb297943e Mon Sep 17 00:00:00 2001 From: Oliver Ni Date: Wed, 4 Oct 2023 23:21:52 -0700 Subject: [PATCH] Automatically provision icalviews and show link --- hknweb/events/models/ical_view.py | 5 +++++ hknweb/events/models/rsvp.py | 12 +++++++----- hknweb/events/views/aggregate_displays/calendar.py | 8 ++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/hknweb/events/models/ical_view.py b/hknweb/events/models/ical_view.py index bbb292eb..d665cae8 100644 --- a/hknweb/events/models/ical_view.py +++ b/hknweb/events/models/ical_view.py @@ -3,6 +3,7 @@ import icalendar from django.conf import settings from django.db import models +from django.urls import reverse from hknweb.events.utils import get_events @@ -16,6 +17,10 @@ class Meta: show_rsvpd = models.BooleanField(default=True) show_not_rsvpd = models.BooleanField(default=False) + @property + def url(self): + return reverse("events:ical", args=[self.id]) + def to_ical_obj(self): cal = icalendar.Calendar() cal.add("prodid", "-//Eta Kappa Nu, Mu Chapter//Calendar//EN") diff --git a/hknweb/events/models/rsvp.py b/hknweb/events/models/rsvp.py index b87a1b82..87788bf7 100644 --- a/hknweb/events/models/rsvp.py +++ b/hknweb/events/models/rsvp.py @@ -1,9 +1,9 @@ -from django.db import models from django.contrib.auth.models import User +from django.db import models -from hknweb.models import Profile -from hknweb.events.models.event import Event import hknweb.events.google_calendar_utils as gcal +from hknweb.events.models.event import Event +from hknweb.models import Profile class Rsvp(models.Model): @@ -30,8 +30,10 @@ def has_not_rsvpd(cls, user, event): def save(self, *args, **kwargs): profile = Profile.objects.filter(user=self.user).first() if not profile.google_calendar_id: - profile.google_calendar_id = gcal.create_personal_calendar() - profile.save() + # we no longer provision new personal google calendars + # instead, we generate a ICalView and a route to view it + # so they can add it to any calendar app + return if self.google_calendar_event_id is None: self.google_calendar_event_id = gcal.create_event( diff --git a/hknweb/events/views/aggregate_displays/calendar.py b/hknweb/events/views/aggregate_displays/calendar.py index 4d037d14..5f3a82e1 100644 --- a/hknweb/events/views/aggregate_displays/calendar.py +++ b/hknweb/events/views/aggregate_displays/calendar.py @@ -91,6 +91,14 @@ def get_calendars(request, user_access_level: int): } ) + ical_view, _ = ICalView.objects.get_or_create(user=request.user) + calendars.append( + { + "name": "personal (ics)", + "link": get_calendar_link(calendar_id=ical_view.url), + } + ) + for calendar in calendars[:-1]: calendar["separator"] = "/" if len(calendars) > 0: