I'm trying to write a view into my Django application that an external calendar application can subscribe to. For example, in Google Calendar, you can "Add a calendar from a URL". This is what I want to create so that I can automatically add new events without my users having to download new files.
As far as I can tell from other, functional URLs, the only thing such a URL needs to do is return a .ics
file without having to authenticate. While I believe I've done that, Google Calendar (and other calendar applications) don't seem to be importing my feed.
The interesting thing to me is that when I visit the URL in my browser, it starts downloading a .ics
file right away. Even more weirdly, when I then try importing that file in Google Calendar with the Import & Export function, the application displays the events in my feed just fine.
Below is an excerpt from the file that is downloaded. Its name is pre-u.ics
.
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//UT Pre-U//Portal//NL
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Pre-U Agenda
X-WR-TIMEZONE:Europe/Amsterdam
BEGIN:VEVENT
SUMMARY:Test event
DTSTART;VALUE=DATE-TIME:20221104T150000Z
DTSTAMP;VALUE=DATE-TIME:20221027T122423Z
UID:gebeurtenis1@pre-u-portal
CATEGORIES:
DESCRIPTION:Test
LOCATION:Unknown
ORGANIZER:MAILTO:myemailaddress@gmail.com
STATUS:CONFIRMED
URL:https://google.com/
END:VEVENT
END:VCALENDAR
I generate the file with the django-ical
package and the following code:
import datetime
from django_ical.views import ICalFeed
from icalendar import vCalAddress, vText
class EventFeed(ICalFeed):
"""
A simple event calender
"""
product_id = "-//UT Pre-U//Portal//NL"
timezone = "Europe/Amsterdam"
file_name = "pre-u.ics"
title = "Pre-U Agenda"
def __init__(self):
self.temp_items = []
def items(self):
self.temp_items = []
for g in Event.objects.all().order_by("-date"):
self.temp_items.append(
{
"type": "event",
"id": g.id,
"name": g.name,
"description": g.description,
"start": g.datum,
"end": None,
"location": None,
}
)
return self.temp_items
def item_title(self, item):
return item["name"]
def item_guid(self, item):
return item["type"] + str(item["id"]) + "@pre-u-portal"
def item_description(self, item):
return item["description"]
def item_start_datetime(self, item):
return item["start"]
def item_end_datetime(self, item):
return item["end"]
def item_location(self, item):
if item["location"]:
return item["location"]
return "Unknown"
def item_status(self, _):
return "CONFIRMED"
def item_organizer(self, _):
return vCalAddress("MAILTO:myemailaddress@gmail.com")
def item_link(self, _):
return "https://portal.pre-u.utwente.nl/"
I don't see what's wrong, help would be greatly appreciated.