Skip to content
Snippets Groups Projects

Calendar events and iCal feeds

Merged Jonathan Weth requested to merge calendar-object-feeds into master
1 file
+ 5
4
Compare changes
  • Side-by-side
  • Inline
+ 5
4
from io import BytesIO
from textwrap import wrap
from typing import Any, Dict, Optional, Type
from urllib.parse import urlencode, urlparse, urlunparse
@@ -1523,13 +1522,15 @@ class CustomAuthorizationView(AuthorizationView):
class ICalFeedView(PermissionRequiredMixin, View):
"""View to generate an iCal feed for a calendar."""
permission_required = "core.view_calendar_feed_rule"
def get(self, request, name, *args, **kwargs):
if name in CalendarEventMixin.registered_objects_dict:
calendar = CalendarEventMixin.registered_objects_dict[name]
feed = calendar.create_feed(request)
ical_file = BytesIO()
feed.write(ical_file, "utf-8")
return HttpResponse(ical_file.getvalue(), content_type="text/calendar")
response = HttpResponse(content_type="text/calendar")
feed.write(response, "utf-8")
return response
raise Http404
Loading