def event_resource(cls, event, for_update=False):
        """Create an event resource to send in the body of a Google Calendar
        API request.

        :param event: The event to translate to an event resource.
        :type event: :class:`Event`
        :param bool for_update: True if the resource is being used in a call to
            update Google Calendar (in which case an extra ``sequence`` field
            is required).

        :raises: :class:`EventumError.GCalAPI.EventMustEndOnOrAfter`

        :returns: An event resource
        :rtype: dict
        """

        resource = {}
        resource['summary'] = event.title
        resource['location'] = event.location
        resource['description'] = clean_markdown(
            event.long_description_markdown
        )
        resource['status'] = 'confirmed' if event.published else 'tentative'
        if for_update:
            resource['sequence'] = event.gcal_sequence + 1

        rfc3339_start_dt = cls.rfc3339(event.start_datetime)
        rfc3339_end_dt = cls.rfc3339(event.end_datetime)

        resource['start'] = {}
        resource['start']['dateTime'] = rfc3339_start_dt
        resource['start']['timeZone'] = cls.EASTERN.zone
        resource['end'] = {}
        resource['end']['dateTime'] = rfc3339_end_dt
        resource['end']['timeZone'] = cls.EASTERN.zone

        if event.is_recurring:
            recurrence = cls._recurrence(event.parent_series)
            resource['recurrence'] = [recurrence]

        return resource
    def event_resource(cls, event, for_update=False):
        """Create an event resource to send in the body of a Google Calendar
        API request.

        :param event: The event to translate to an event resource.
        :type event: :class:`Event`
        :param bool for_update: True if the resource is being used in a call to
            update Google Calendar (in which case an extra ``sequence`` field
            is required).

        :raises: :class:`EventumError.GCalAPI.EventMustEndOnOrAfter`

        :returns: An event resource
        :rtype: dict
        """

        resource = {}
        resource['summary'] = event.title
        resource['location'] = event.location
        resource['description'] = clean_markdown(
            event.long_description_markdown)
        resource['status'] = 'confirmed' if event.published else 'tentative'
        if for_update:
            resource['sequence'] = event.gcal_sequence + 1

        rfc3339_start_dt = cls.rfc3339(event.start_datetime)
        rfc3339_end_dt = cls.rfc3339(event.end_datetime)

        resource['start'] = {}
        resource['start']['dateTime'] = rfc3339_start_dt
        resource['start']['timeZone'] = cls.EASTERN.zone
        resource['end'] = {}
        resource['end']['dateTime'] = rfc3339_end_dt
        resource['end']['timeZone'] = cls.EASTERN.zone

        if event.is_recurring:
            recurrence = cls._recurrence(event.parent_series)
            resource['recurrence'] = [recurrence]

        return resource
示例#3
0
 def test_clean_markdown(self):
     for md_in, md_out in self.MARKDOWN_EXPECTATIONS:
         output = clean_markdown(md_in)
         self.assertEqual(output,
                          md_out,
                          msg=self.ERROR_MSG.format(md_out, output))