def _create_icalendar_event(event: Event) -> IEvent: """Returns an iCalendar event with event data. Args: event: The Event to transform into an iCalendar event. Returns: An iCalendar event. """ data = [ ('organizer', _get_v_cal_address(event.owner.email, organizer=True)), ('uid', _generate_id(event)), ('dtstart', event.start), ('dtstamp', datetime.now(tz=pytz.utc)), ('dtend', event.end), ('summary', event.title), ] if event.location: data.append(('location', event.location)) if event.content: data.append(('description', event.content)) ievent = IEvent() for param in data: ievent.add(*param) return ievent
def ical(self) -> Calendar: """Get ical representation of event""" cal = Calendar() event = IEvent() event.add("summary", "Video Chat") event.add("dtstart", self.start) cal.add_component(event) return cal.to_ical()
def to_ical_event(self) -> IEvent: dtstart = datetime(self.year, self.month_from, self.day_from) dtend = datetime(self.year, self.month_to, self.day_to) dtend += timedelta(days=+1) e = IEvent() e.add("summary", self.subject) e.add("dtstart", vDate(dtstart)) e.add("dtend", vDate(dtend)) return e
def _make_ievent(ev): iev = IEvent() iev.add('summary', ev.title) iev.add('url', 'http://{domain}{url}'.format( domain=_get_current_domain(), url=ev.get_absolute_url(), )) iev.add('location', ev.location) iev.add('dtstamp', datetime.combine(ev.date, ev.start_time)) iev.add('dtstart', datetime.combine(ev.date, ev.start_time)) iev.add('dtend', datetime.combine(ev.date, ev.end_time)) iev['uid'] = "event-{id}@{domain}".format( id=ev.id, domain=_get_current_domain(), ) return iev
def get_icalendar_event(self): """ Builds an icalendar.event object from event data. """ icalendar_event = IEvent() icalendar_event.add('summary'.encode("utf-8"), self.title) icalendar_event.add('url', 'http://{domain}{url}'.format( domain=Site.objects.get(id=current_site_id()).domain, url=self.get_absolute_url(), )) if self.location: icalendar_event.add('location'.encode("utf-8"), self.location.address) icalendar_event.add('dtstamp', self.start) icalendar_event.add('dtstart', self.start) if self.end: icalendar_event.add('dtend', self.end) icalendar_event['uid'.encode("utf-8")] = "event-{id}@{domain}".format( id=self.id, domain=Site.objects.get(id=current_site_id()).domain, ).encode("utf-8") return icalendar_event
def ical(request): t = loader.get_template(calendar_description_template) token = get_token(request) if not token: return HttpResponseForbidden("Missing authentication token") try: key = Key.objects.select_related("user").get(token=token) except Key.DoesNotExist: return HttpResponseForbidden("Invalid authentication token") if not key.has_scopes(["export_ical"]): return HttpResponseForbidden("Unauthorized operation for the token") key.update_used_on() cal = Calendar() cal.add("prodid", f"-//small-eod//letters//{key.user}//") cal.add("version", "2.0") for name in refresh_props: cal.add(name, "PT1H") for obj in Letter.objects.exclude(event__isnull=True).select_related( "case", "case__audited_institution"): letter = IEvent() url = request.build_absolute_uri( reverse("admin:cases_letter_change", kwargs={"object_id": str(obj.pk)})) description = t.render({"obj": obj}, request).strip() categories = [obj.case] if obj.case and obj.case.audited_institution: categories.append(obj.case.audited_institution) letter.add("uid", get_uuid(obj, description)) letter.add("dtstart", obj.event) letter.add("dtstamp", obj.event) letter.add("summary", obj.name) letter.add("url", url) if description: letter.add("description", description) letter.add("categories", categories) cal.add_component(letter) return HttpResponse(content=cal.to_ical(), content_type="text/calendar")
def ical(request): cal = Calendar() cal.add('prodid', '-//%s Events Calendar//%s//' % ("URNIK", "DELAJOZATE")) cal.add('version', '2.0') site_token = "DELAJOZATE" startdate = datetime.date.today() - datetime.timedelta(1) events = Event.objects.filter( start__gte=startdate).order_by('start')[:NUM_EVENTS] for e in events: ical_event = IEvent() ical_event.add('summary', e.title) ical_event.add('dtstart', e.start) ical_event.add('dtend', e.end) ical_event.add('location', e.location) ical_event.add('description', e.category + " " + str(e.url)) ical_event['uid'] = '%d.event.events.%s' % (e.id, site_token) cal.add_component(ical_event) response = HttpResponse(cal.to_ical(), mimetype="text/calendar") response['Content-Disposition'] = 'attachment; filename=%s.ics' % "urnik" return response
def ical(request): t = loader.get_template(calendar_description_template) token = get_token(request) if not token: return HttpResponseForbidden("Missing authentication token") try: key = Key.objects.select_related("user").get(token=token) except Key.DoesNotExist: return HttpResponseForbidden("Invalid authentication token") if not key.has_scopes(["export_ical"]): return HttpResponseForbidden("Unauthorized operation for the token") key.update_used_on() cal = Calendar() cal.add("prodid", f"-//small-eod//events//{key.user}//") cal.add("version", "2.0") for obj in Event.objects.select_related("case", "case__audited_institution"): event = IEvent() url = request.build_absolute_uri( reverse("admin:events_event_change", kwargs={"object_id": str(obj.case.pk)})) description = t.render({"obj": obj}, request) categories = [obj.case] if obj.case.audited_institution: categories.append(obj.case.audited_institution) event.add("uid", url) event.add("dtstart", obj.date) event.add("dtstamp", obj.date) event.add("summary", obj.name) event.add("created", obj.created_on) event.add("last-modified", obj.modified_on) event.add("url", url) event.add("description", description) event.add("categories", categories) cal.add_component(event) return HttpResponse(content=cal.to_ical(), content_type="text/calendar")
def generateCalendar(event_category_ids=None): events = eventService.getEventWithCategories(event_category_ids) now = HEL.localize(datetime.now()) cal = ICalendar() cal['version'] = "2.0" cal['METHOD'] = 'PUBLISH' cal['prodid'] = "-//Aalto//CS-E4400//Student Event Manager" for event in events: iEvent = IEvent() iEvent['uid'] = str(event.id) + '@aalto-student-event-manager.fi' iEvent['Summary'] = event.title iEvent['location'] = event.place iEvent['Description'] = event.description iEvent['dtstart'] = (event.start_date + timedelta(hours=-2)).strftime(fmt) iEvent['dtend'] = (event.end_date + timedelta(hours=-2)).strftime(fmt) iEvent['dtstamp'] = now.strftime(fmt) categories = [] for category in event.event_categories: categories.append(category.name) iEvent['categories'] = ','.join(categories) cal.add_component(iEvent) return cal.to_ical()