<s> from django . http import HttpResponse <EOL> from django . utils . feedgenerator import SyndicationFeed <EOL> import vobject <EOL> FEED_ICAL_MAP = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ITEM_ICAL_MAP = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT:description>' , <EOL> '<STR_LIT>' : '<STR_LIT:url>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : '<STR_LIT>' , <EOL> '<STR_LIT:end>' : '<STR_LIT>' , <EOL> } <EOL> class ICalendarFeed ( SyndicationFeed ) : <EOL> mime_type = '<STR_LIT>' <EOL> def add_item ( self , * args , ** kwargs ) : <EOL> for kwarg in [ '<STR_LIT:start>' , '<STR_LIT:end>' , '<STR_LIT>' , '<STR_LIT:location>' ] : <EOL> kwargs . setdefault ( kwarg , None ) <EOL> super ( ICalendarFeed , self ) . add_item ( * args , ** kwargs ) <EOL> def write ( self , outfile , encoding ) : <EOL> cal = vobject . iCalendar ( ) <EOL> cal . add ( '<STR_LIT>' ) . value = '<STR_LIT>' <EOL> for key , val in self . feed . items ( ) : <EOL> if key in FEED_ICAL_MAP and val : <EOL> cal . add ( FEED_ICAL_MAP [ key ] ) . value = val <EOL> for item in self . items : <EOL> event = cal . add ( '<STR_LIT>' ) <EOL> for key , val in item . items ( ) : <EOL> if key in ITEM_ICAL_MAP and val : <EOL> event . add ( ITEM_ICAL_MAP [ key ] ) . value = val <EOL> cal . serialize ( outfile ) <EOL> if isinstance ( outfile , HttpResponse ) : <EOL> filename = self . feed . get ( '<STR_LIT:filename>' , '<STR_LIT>' ) <EOL> outfile [ '<STR_LIT>' ] = filename <EOL> outfile [ '<STR_LIT>' ] = '<STR_LIT>' % filename </s>
