X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/82b08f79564159d7acbcaf255ed1ac1fb4882e64..d19e216035b14d8f60b24dda0c0670e6997f16ce:/contrib/julian/feedgenerator.py diff --git a/contrib/julian/feedgenerator.py b/contrib/julian/feedgenerator.py deleted file mode 100644 index 819a273..0000000 --- a/contrib/julian/feedgenerator.py +++ /dev/null @@ -1,77 +0,0 @@ -from django.http import HttpResponse -from django.utils.feedgenerator import SyndicationFeed -import vobject - - -# Map the keys in the ICalendarFeed internal dictionary to the names of iCalendar attributes. -FEED_ICAL_MAP = { - 'title': 'x-wr-calname', - 'description': 'x-wr-caldesc', - #'link': ???, - #'language': ???, - #author_email - #author_name - #author_link - #subtitle - #categories - #feed_url - #feed_copyright - 'id': 'prodid', - 'ttl': 'x-published-ttl' -} - - -ITEM_ICAL_MAP = { - 'title': 'summary', - 'description': 'description', - 'link': 'url', - # author_email, author_name, and author_link need special handling. Consider them the - # 'organizer' of the event and - # construct something based on that. - 'pubdate': 'created', - 'last_modified': 'last-modified', - #'comments' require special handling as well - 'unique_id': 'uid', - 'enclosure': 'attach', # does this need special handling? - 'categories': 'categories', # does this need special handling? - # ttl is ignored. - 'start': 'dtstart', - 'end': 'dtend', -} - - -class ICalendarFeed(SyndicationFeed): - mime_type = 'text/calendar' - - def add_item(self, *args, **kwargs): - for kwarg in ['start', 'end', 'last_modified', 'location']: - kwargs.setdefault(kwarg, None) - super(ICalendarFeed, self).add_item(*args, **kwargs) - - def write(self, outfile, encoding): - # TODO: Use encoding... how? Just convert all values when setting them should work... - cal = vobject.iCalendar() - - # IE/Outlook needs this. See - # - cal.add('method').value = 'PUBLISH' - - for key, val in self.feed.items(): - if key in FEED_ICAL_MAP and val: - cal.add(FEED_ICAL_MAP[key]).value = val - - for item in self.items: - # TODO: handle multiple types of events. - event = cal.add('vevent') - for key, val in item.items(): - #TODO: handle the non-standard items like comments and author. - if key in ITEM_ICAL_MAP and val: - event.add(ITEM_ICAL_MAP[key]).value = val - - cal.serialize(outfile) - - # Some special handling for HttpResponses. See link above. - if isinstance(outfile, HttpResponse): - filename = self.feed.get('filename', 'filename.ics') - outfile['Filename'] = filename - outfile['Content-Disposition'] = 'attachment; filename=%s' % filename \ No newline at end of file