From 6d4bcf8559261af6792711368c8e78c8bf34a94c Mon Sep 17 00:00:00 2001 From: Oliver Ni Date: Wed, 4 Oct 2023 22:52:43 -0700 Subject: [PATCH] Add ical view --- hknweb/events/urls.py | 3 ++- hknweb/events/views/__init__.py | 1 + .../events/views/aggregate_displays/__init__.py | 2 +- .../events/views/aggregate_displays/calendar.py | 16 ++++++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hknweb/events/urls.py b/hknweb/events/urls.py index 1c4244d4..c5cfc5f9 100644 --- a/hknweb/events/urls.py +++ b/hknweb/events/urls.py @@ -1,11 +1,12 @@ from django.urls import path -import hknweb.events.views as views +import hknweb.events.views as views app_name = "events" aggregate_display_urls = [ path("", views.index, name="index"), + path("ical/.ics", views.ical, name="ical"), path("leaderboard", views.get_leaderboard, name="leaderboard"), path("photos", views.photos, name="photos"), ] diff --git a/hknweb/events/views/__init__.py b/hknweb/events/views/__init__.py index 284892fb..488d2ea2 100644 --- a/hknweb/events/views/__init__.py +++ b/hknweb/events/views/__init__.py @@ -1,5 +1,6 @@ from hknweb.events.views.aggregate_displays import ( index, + ical, get_leaderboard, photos, ) diff --git a/hknweb/events/views/aggregate_displays/__init__.py b/hknweb/events/views/aggregate_displays/__init__.py index 8a51e531..710f8df3 100644 --- a/hknweb/events/views/aggregate_displays/__init__.py +++ b/hknweb/events/views/aggregate_displays/__init__.py @@ -1,3 +1,3 @@ -from hknweb.events.views.aggregate_displays.calendar import index +from hknweb.events.views.aggregate_displays.calendar import ical, index from hknweb.events.views.aggregate_displays.leaderboard import get_leaderboard from hknweb.events.views.aggregate_displays.photos import photos diff --git a/hknweb/events/views/aggregate_displays/calendar.py b/hknweb/events/views/aggregate_displays/calendar.py index d6281407..cd95e50f 100644 --- a/hknweb/events/views/aggregate_displays/calendar.py +++ b/hknweb/events/views/aggregate_displays/calendar.py @@ -1,13 +1,15 @@ +import uuid from typing import List -from django.shortcuts import render +from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render -from hknweb.models import Profile -from hknweb.events.models import Event, EventType, GCalAccessLevelMapping +from hknweb.events.google_calendar_utils import get_calendar_link +from hknweb.events.models import Event, EventType, GCalAccessLevelMapping, ICalView from hknweb.events.models.constants import ACCESS_LEVELS from hknweb.events.utils import get_events +from hknweb.models import Profile from hknweb.utils import allow_public_access, get_access_level -from hknweb.events.google_calendar_utils import get_calendar_link @allow_public_access @@ -29,6 +31,12 @@ def index(request): ) +@allow_public_access +def ical(request, *, id: uuid.UUID): + ical_view = get_object_or_404(ICalView, pk=id) + return HttpResponse(ical_view.to_ical_obj().to_ical()) + + def calendar_helper( request, title,