Ejemplo n.º 1
0
    def getICal(self):
        """get iCal data
        """

        start_str, end_str = event_util.dateStringsForEvent(self.context)
        out = StringIO()
        map = {
            'dtstamp'   : rfc2445dt(DateTime()),
            'created'   : rfc2445dt(DateTime(self.context.CreationDate())),
            'uid'       : self.context.UID(),
            'modified'  : rfc2445dt(DateTime(self.context.ModificationDate())),
            'summary'   : vformat(self.context.Title()),
            'startdate' : start_str,
            'enddate'   : end_str,
            }
        out.write(ICS_EVENT_START % map)

        description = self.context.Description()
        if description:
            out.write(foldline('DESCRIPTION:%s\n' % vformat(description)))

        location = self.context.getLocation()
        if location:
            out.write('LOCATION:%s\n' % vformat(location))

        subject = self.context.Subject()
        if subject:
            out.write('CATEGORIES:%s\n' % ','.join(subject))

        # TODO  -- NO! see the RFC; ORGANIZER field is not to be used for non-group-scheduled entities
        #ORGANIZER;CN=%(name):MAILTO=%(email)
        #ATTENDEE;CN=%(name);ROLE=REQ-PARTICIPANT:mailto:%(email)

        cn = []
        contact = self.context.contact_name()
        if contact:
            cn.append(contact)
        phone = self.context.contact_phone()
        if phone:
            cn.append(phone)
        email = self.context.contact_email()
        if email:
            cn.append(email)
        if cn:
            out.write('CONTACT:%s\n' % vformat(', '.join(cn)))

        url = self.context.event_url()
        if url:
            out.write('URL:%s\n' % url)

        # allow derived event types to inject additional data for iCal
        try:
            self.context.getICalSupplementary(out)
        except AttributeError:
            pass

        out.write(ICS_EVENT_END)
        return out.getvalue()