Skip to content

Commit

Permalink
Automatically provision icalviews and show link
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni committed Oct 5, 2023
1 parent 65e714f commit b08c389
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions hknweb/events/models/ical_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down
12 changes: 7 additions & 5 deletions hknweb/events/models/rsvp.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions hknweb/events/views/aggregate_displays/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b08c389

Please sign in to comment.