Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
encoding='UTF-8')
class FeedEmitter(Emitter):
"""
Emits an RSS feed from a list of billy 'event' objects.
Expects a list of objects from the handler. Non-event objects will be
ignored.
"""
def render(self, request):
return EventFeed()(request, self.construct())
class _vDatetime(icalendar.vDatetime):
"""
The icalendar module outputs datetimes with VALUE=DATE,
which breaks some calendar clients. This is a fix to
use VALUE=DATETIME.
"""
def __init__(self, dt):
self.dt = dt
self.params = icalendar.Parameters(dict(value='DATETIME'))
class ICalendarEmitter(Emitter):
"""
Emits an iCalendar-format calendar from a list of 'event' objects.
Expects a list of objects from the handler. Non-event objects will be
ignored.
def build_reservations_ical_file(reservations):
"""
Return iCalendar file containing given reservations
"""
cal = Calendar()
for reservation in reservations:
event = Event()
begin_utc = timezone.localtime(reservation.begin, timezone.utc)
end_utc = timezone.localtime(reservation.end, timezone.utc)
event['uid'] = 'respa_reservation_{}'.format(reservation.id)
event['dtstart'] = vDatetime(begin_utc)
event['dtend'] = vDatetime(end_utc)
unit = reservation.resource.unit
event['location'] = vText('{} {} {}'.format(unit.name, unit.street_address, unit.address_zip))
if unit.location:
event['geo'] = vGeo(unit.location)
event['summary'] = vText('{} {}'.format(unit.name, reservation.resource.name))
cal.add_component(event)
return cal.to_ical()
Time
Description and Place
'''
year = None
for cal in entries:
print("cal['DTSTART'] = %s" % cal['DTSTART'])
# cal['DTSTART'] might be a icalendar.prop.vDDDTypes object
# or it might be a string. Handle either type:
try:
starttime = cal['DTSTART'].dt
except AttributeError:
starttime = vDatetime.from_ical(cal['DTSTART'])
if not year or starttime.year != year:
year = starttime.year
html += '''
<h4>%d</h4>
''' % year
datestr = starttime.strftime("%A,<br>%B %d")
timestr = ""
html += '''
%s%s
<span class="alert">%s''' \
% (datestr, timestr, cal['SUMMARY'])
# Seems like it would be better to use
# cal['SUMMARY'].encode('utf-8', 'xmlcharrefreplace'))</span>
def course_to_event(course):
"""Convert a Course into a icalendar event.
:param course: a :class:`tradeschool.models.Course` to export as an Event
:returns: :class:`icalendar.Event`
"""
return Event(**{
'uid': vText(_build_uid_for_course(course)),
'created': vDatetime(course.created),
'description': vText(course.description),
'dtstart': vDatetime(course.start_time),
'dtend': vDatetime(course.end_time),
'last-mod': vDatetime(course.updated),
'dtstamp': vDatetime(datetime.datetime.now()),
'location': vText(_build_location_for_venue(course.venue)),
'summary': vText(course.title),
'url': vUri(course.course_view_url),
})
def course_to_event(course):
"""Convert a Course into a icalendar event.
:param course: a :class:`tradeschool.models.Course` to export as an Event
:returns: :class:`icalendar.Event`
"""
return Event(**{
'uid': vText(_build_uid_for_course(course)),
'created': vDatetime(course.created),
'description': vText(course.description),
'dtstart': vDatetime(course.start_time),
'dtend': vDatetime(course.end_time),
'last-mod': vDatetime(course.updated),
'dtstamp': vDatetime(datetime.datetime.now()),
'location': vText(_build_location_for_venue(course.venue)),
'summary': vText(course.title),
'url': vUri(course.course_view_url),
})
def course_to_event(course):
"""Convert a Course into a icalendar event.
:param course: a :class:`tradeschool.models.Course` to export as an Event
:returns: :class:`icalendar.Event`
"""
return Event(**{
'uid': vText(_build_uid_for_course(course)),
'created': vDatetime(course.created),
'description': vText(course.description),
'dtstart': vDatetime(course.start_time),
'dtend': vDatetime(course.end_time),
'last-mod': vDatetime(course.updated),
'dtstamp': vDatetime(datetime.datetime.now()),
'location': vText(_build_location_for_venue(course.venue)),
'summary': vText(course.title),
'url': vUri(course.course_view_url),
})
def course_to_event(course):
"""Convert a Course into a icalendar event.
:param course: a :class:`tradeschool.models.Course` to export as an Event
:returns: :class:`icalendar.Event`
"""
return Event(**{
'uid': vText(_build_uid_for_course(course)),
'created': vDatetime(course.created),
'description': vText(course.description),
'dtstart': vDatetime(course.start_time),
'dtend': vDatetime(course.end_time),
'last-mod': vDatetime(course.updated),
'dtstamp': vDatetime(datetime.datetime.now()),
'location': vText(_build_location_for_venue(course.venue)),
'summary': vText(course.title),
'url': vUri(course.course_view_url),
})