1 from django.utils.feedgenerator import SyndicationFeed
5 # Map the keys in the ICalendarFeed internal dictionary to the names of iCalendar attributes.
7 'title': 'x-wr-calname',
8 'description': 'x-wr-caldesc',
19 'ttl': 'x-published-ttl'
25 'description': 'description',
27 # author_email, author_name, and author_link need special handling. Consider them the
28 # 'organizer' of the event <http://tools.ietf.org/html/rfc5545#section-3.8.4.3> and
29 # construct something based on that.
31 'last_modified': 'last-modified',
32 #'comments' require special handling as well <http://tools.ietf.org/html/rfc5545#section-3.8.1.4>
34 'enclosure': 'attach', # does this need special handling?
35 'categories': 'categories', # does this need special handling?
42 class ICalendarFeed(SyndicationFeed):
43 #def __init__(self, title, link, description, language=None, author_email=None,
44 # author_name=None, author_link=None, subtitle=None, categories=None,
45 # feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
46 # super(ICalendarFeed, self).__init__(title, link, description, language,
47 # author_email, author_name, author_link, subtitle, categories,
48 # feed_url, feed_copyright, feed_guid, ttl, **kwargs)
50 mime_type = 'text/calendar'
52 def add_item(self, *args, **kwargs):
53 for kwarg in ['start', 'end', 'last_modified', 'location']:
54 kwargs.setdefault(kwarg, None)
55 super(ICalendarFeed, self).add_item(*args, **kwargs)
57 def write(self, outfile, encoding):
58 # TODO: Use encoding... how? Just convert all values when setting them should work...
59 cal = vobject.iCalendar()
61 # IE/Outlook needs this. See
62 # <http://blog.thescoop.org/archives/2007/07/31/django-ical-and-vobject/>
63 cal.add('method').value = 'PUBLISH'
65 for key, val in self.feed.items():
66 if key in FEED_ICAL_MAP and val:
67 cal.add(FEED_ICAL_MAP[key]).value = val
69 for item in self.items:
70 # TODO: handle multiple types of events.
71 event = cal.add('vevent')
72 for key, val in item.items():
73 #TODO: handle the non-standard items like comments and author.
74 if key in ITEM_ICAL_MAP and val:
75 event.add(ITEM_ICAL_MAP[key]).value = val
77 cal.serialize(outfile)