示例#1
0
    def update_single_event(klass, event, form, move_to=None):
        """Updates the non-recurring ``event``, syncing changes to Google
        Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = klass._remove_none_fields(event_and_date_data)
        klass._update_event(event, event_and_date_data)

        # Update the event in Google Calendar and publish it as necessary
        if move_to == klass.PUBLIC:
            response = gcal_client.publish_event(event)
        elif move_to == klass.PRIVATE:
            response = gcal_client.unpublish_event(event)
        response = gcal_client.update_event(event)

        # Return the Google Calendar response
        return response
示例#2
0
    def convert_to_single_event(cls, event, form, move_to=None):
        """Converts ``event`` from a series to a single event, updating other
        fields and syncing changes to Google Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        event.parent_series.delete_all_except(event)
        cls._update_event(event, date_data, event_data)

        # Delete the series and create a single event
        return gcal_client.update_event(event)
示例#3
0
    def convert_to_series(klass, event, form, move_to=None):
        """"""
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        # Make the parent series
        series = klass._make_series(form, gcal_id=event.gcal_id)

        # Update event_data with the parent series
        event_data['parent_series'] = series
        event_data['creator'] = event.creator
        event_data['gcal_id'] = event.gcal_id

        klass._update_event(event, event_data, date_data)
        series.events.append(event)
        klass._increment_date_data(series, date_data)

        # Make the individual Event objects in the series
        while klass._more_events(series, date_data):
            ev = klass._make_event(event_data, date_data)
            series.events.append(ev)
            klass._increment_date_data(series, date_data)

        series.save()

        # Return the Google Calendar response
        return gcal_client.update_event(series.events[0])
示例#4
0
    def update_single_event_from_series(klass, event, form):
        """Updates the ``event`` as an exception to a series, syncing changes
        to Google Calendar.

        The parameter ``move_to`` is not implemented in this method because
        having multiple events in a series on different calendars is not
        possible.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = klass._remove_none_fields(event_and_date_data)
        klass._update_event(event, event_and_date_data)

        # Return Google Calendar response
        return gcal_client.update_event(event, as_exception=True)
示例#5
0
    def update_single_event_from_series(cls, event, form):
        """Updates the ``event`` as an exception to a series, syncing changes
        to Google Calendar.

        The parameter ``move_to`` is not implemented in this method because
        having multiple events in a series on different calendars is not
        possible.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = cls._remove_none_fields(event_and_date_data)
        cls._update_event(event, event_and_date_data)

        # Return Google Calendar response
        return gcal_client.update_event(event, as_exception=True)
示例#6
0
    def update_single_event(cls, event, form, move_to=None):
        """Updates the non-recurring ``event``, syncing changes to Google
        Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = cls._remove_none_fields(event_and_date_data)
        cls._update_event(event, event_and_date_data)

        # Update the event in Google Calendar and publish it as necessary
        if move_to == cls.PUBLIC:
            response = gcal_client.publish_event(event)
        elif move_to == cls.PRIVATE:
            response = gcal_client.unpublish_event(event)
        response = gcal_client.update_event(event)

        # Return the Google Calendar response
        return response
示例#7
0
    def convert_to_series(klass, event, form, move_to=None):
        """"""
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        # Make the parent series
        series = klass._make_series(form, gcal_id=event.gcal_id)

        # Update event_data with the parent series
        event_data['parent_series'] = series
        event_data['creator'] = event.creator
        event_data['gcal_id'] = event.gcal_id

        klass._update_event(event, event_data, date_data)
        series.events.append(event)
        klass._increment_date_data(series, date_data)

        # Make the individual Event objects in the series
        while klass._more_events(series, date_data):
            ev = klass._make_event(event_data, date_data)
            series.events.append(ev)
            klass._increment_date_data(series, date_data)

        series.save()

        # Return the Google Calendar response
        return gcal_client.update_event(series.events[0])
示例#8
0
    def convert_to_single_event(klass, event, form, move_to=None):
        """Converts ``event`` from a series to a single event, updating other
        fields and syncing changes to Google Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        event.parent_series.delete_all_except(event)
        klass._update_event(event, date_data, event_data)

        # Delete the series and create a single event
        return gcal_client.update_event(event)
示例#9
0
    def update_single_event_from_series(klass, event, form):
        """"""
        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = klass._remove_none_fields(event_and_date_data)
        klass._update_event(event, event_and_date_data)

        # Return Google Calendar response
        return gcal_client.update_event(event, as_exception=True)
示例#10
0
    def update_single_event_from_series(klass, event, form):
        """"""
        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = klass._remove_none_fields(event_and_date_data)
        klass._update_event(event, event_and_date_data)

        # Return Google Calendar response
        return gcal_client.update_event(event, as_exception=True)
示例#11
0
    def convert_to_single_event(klass, event, form, move_to=None):
        """"""
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        event.parent_series.delete_all_except(event)
        klass._update_event(event, date_data, event_data)

        # Delete the series and create a single event
        return gcal_client.update_event(event)
示例#12
0
    def convert_to_single_event(klass, event, form, move_to=None):
        """"""
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        event.parent_series.delete_all_except(event)
        klass._update_event(event, date_data, event_data)

        # Delete the series and create a single event
        return gcal_client.update_event(event)
示例#13
0
    def update_single_event(klass, event, form, move_to=None):
        """"""
        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = klass._remove_none_fields(event_and_date_data)
        klass._update_event(event, event_and_date_data)

        # Update the event and publish it as necessary
        if move_to == klass.PUBLIC:
            response = gcal_client.publish_event(event)
        elif move_to == klass.PRIVATE:
            response = gcal_client.unpublish_event(event)
        response = gcal_client.update_event(event)

        # Return the Google Calendar response
        return response
示例#14
0
    def update_single_event(klass, event, form, move_to=None):
        """"""
        event_and_date_data = DataBuilder.event_and_date_data_from_form(form)
        event_and_date_data = klass._remove_none_fields(event_and_date_data)
        klass._update_event(event, event_and_date_data)

        # Update the event and publish it as necessary
        if move_to == klass.PUBLIC:
            response = gcal_client.publish_event(event)
        elif move_to == klass.PRIVATE:
            response = gcal_client.unpublish_event(event)
        response = gcal_client.update_event(event)

        # Return the Google Calendar response
        return response
示例#15
0
    def convert_to_series(cls, event, form, move_to=None):
        """Converts ``event`` to be a series and updates other fields, syncing
        changes to Google Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        # Make the parent series
        series = cls._make_series(form, gcal_id=event.gcal_id)

        # Update event_data with the parent series
        event_data['parent_series'] = series
        event_data['creator'] = event.creator
        event_data['gcal_id'] = event.gcal_id

        cls._update_event(event, event_data, date_data)
        series.events.append(event)
        cls._increment_date_data(series, date_data)

        # Make the individual Event objects in the series
        while cls._more_events(series, date_data):
            ev = cls._make_event(event_data, date_data)
            series.events.append(ev)
            cls._increment_date_data(series, date_data)

        series.save()

        # Return the Google Calendar response
        return gcal_client.update_event(series.events[0])
示例#16
0
    def update_series(klass, event, form, move_to=None):
        """"""
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        # Make the parent series
        series_data = DataBuilder.series_data_from_form(form)
        klass._validate_series_data(series_data)

        if klass._changes_are_easy(event, series_data, date_data):
            for e in event.parent_series.events:
                # the date data isn't changing, so pass in {}
                klass._update_event(e, event_data, {})
            series = event.parent_series
        else:
            shared_gcal_id = event.gcal_id
            shared_gcal_sequence = event.gcal_sequence
            shared_creator = event.creator

            event.parent_series.delete_all()
            series = klass._make_series(None,
                                        gcal_id=shared_gcal_id,
                                        **series_data)

            # Update event_data with the parent series
            event_data['parent_series'] = series
            event_data['gcal_id'] = shared_gcal_id
            event_data['gcal_sequence'] = shared_gcal_sequence
            event_data['creator'] = shared_creator

            # Make the individual Event objects in the series
            while klass._more_events(series, date_data):
                ev = klass._make_event(event_data, date_data)
                series.events.append(ev)
                klass._increment_date_data(series, date_data)

            series.save()

        if move_to == klass.PUBLIC:
            response = gcal_client.publish_event(series.events[0])
        elif move_to == klass.PRIVATE:
            response = gcal_client.unpublish_event(series.events[0])
        response = gcal_client.update_event(series.events[0])
        return response
示例#17
0
    def convert_to_series(klass, event, form, move_to=None):
        """Converts ``event`` to be a series and updates other fields, syncing
        changes to Google Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        # Make the parent series
        series = klass._make_series(form, gcal_id=event.gcal_id)

        # Update event_data with the parent series
        event_data['parent_series'] = series
        event_data['creator'] = event.creator
        event_data['gcal_id'] = event.gcal_id

        klass._update_event(event, event_data, date_data)
        series.events.append(event)
        klass._increment_date_data(series, date_data)

        # Make the individual Event objects in the series
        while klass._more_events(series, date_data):
            ev = klass._make_event(event_data, date_data)
            series.events.append(ev)
            klass._increment_date_data(series, date_data)

        series.save()

        # Return the Google Calendar response
        return gcal_client.update_event(series.events[0])
示例#18
0
    def update_series(klass, event, form, move_to=None):
        """"""
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)

        # Make the parent series
        series_data = DataBuilder.series_data_from_form(form)
        klass._validate_series_data(series_data)

        if klass._changes_are_easy(event, series_data, date_data):
            for e in event.parent_series.events:
                # the date data isn't changing, so pass in {}
                klass._update_event(e, event_data, {})
            series = event.parent_series
        else:
            shared_gcal_id = event.gcal_id
            shared_gcal_sequence = event.gcal_sequence
            shared_creator = event.creator

            event.parent_series.delete_all()
            series = klass._make_series(None, gcal_id=shared_gcal_id, **series_data)

            # Update event_data with the parent series
            event_data['parent_series'] = series
            event_data['gcal_id'] = shared_gcal_id
            event_data['gcal_sequence'] = shared_gcal_sequence
            event_data['creator'] = shared_creator

            # Make the individual Event objects in the series
            while klass._more_events(series, date_data):
                ev = klass._make_event(event_data, date_data)
                series.events.append(ev)
                klass._increment_date_data(series, date_data)

            series.save()

        if move_to == klass.PUBLIC:
            response = gcal_client.publish_event(series.events[0])
        elif move_to == klass.PRIVATE:
            response = gcal_client.unpublish_event(series.events[0])
        response = gcal_client.update_event(series.events[0])
        return response
示例#19
0
    def update_series(klass, event, form, move_to=None):
        """Updates the recurring ``event``, syncing changes to Google Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        # Build the event, date, and series data, validating the series data.
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)
        series_data = DataBuilder.series_data_from_form(form)
        klass._validate_series_data(series_data)

        if klass._changes_are_easy(event, series_data, date_data):
            # If changes are easy, then we can make them on the Event objects
            # that already exist.
            for e in event.parent_series.events:
                # the date data isn't changing, so pass in {}
                klass._update_event(e, event_data, {})
            series = event.parent_series
        else:
            # Otherwise, they changes are hard, and we have to create fresh
            # Events.
            shared_gcal_id = event.gcal_id
            shared_gcal_sequence = event.gcal_sequence
            shared_creator = event.creator

            event.parent_series.delete_all()
            series = klass._make_series(None,
                                        gcal_id=shared_gcal_id,
                                        **series_data)

            # Update event_data with the parent series
            event_data['parent_series'] = series
            event_data['gcal_id'] = shared_gcal_id
            event_data['gcal_sequence'] = shared_gcal_sequence
            event_data['creator'] = shared_creator

            # Make the individual Event objects in the series
            while klass._more_events(series, date_data):
                ev = klass._make_event(event_data, date_data)
                series.events.append(ev)
                klass._increment_date_data(series, date_data)

            series.save()

        # Update the event in Google Calendar and publish it as necessary
        if move_to == klass.PUBLIC:
            response = gcal_client.publish_event(series.events[0])
        elif move_to == klass.PRIVATE:
            response = gcal_client.unpublish_event(series.events[0])
        response = gcal_client.update_event(series.events[0])

        # Return Google Calendar response
        return response
示例#20
0
    def update_series(cls, event, form, move_to=None):
        """Updates the recurring ``event``, syncing changes to Google Calendar.

        If ``move_to`` is set to ``"public"`` or ``"private"`` the event
        will also be moved to that calendar.

        :param event: The event to update.
        :type event: :class:`Event`
        :param form: The WTForms form from which the updates come.
        :type form: :class:`CreateEventForm` or a subclass.
        :param str move_to: The calendar to move the event to, if any.

        :raises: :class:`GoogleCalendarAPIError` and it's subclasses

        :returns: Response from the Google Calendar API.
        :rtype: dict
        """

        # Build the event, date, and series data, validating the series data.
        event_data = DataBuilder.event_data_from_form(form)
        date_data = DataBuilder.date_data_from_form(form)
        series_data = DataBuilder.series_data_from_form(form)
        cls._validate_series_data(series_data)

        if cls._changes_are_easy(event, series_data, date_data):
            # If changes are easy, then we can make them on the Event objects
            # that already exist.
            for e in event.parent_series.events:
                # the date data isn't changing, so pass in {}
                cls._update_event(e, event_data, {})
            series = event.parent_series
        else:
            # Otherwise, they changes are hard, and we have to create fresh
            # Events.
            shared_gcal_id = event.gcal_id
            shared_gcal_sequence = event.gcal_sequence
            shared_creator = event.creator

            event.parent_series.delete_all()
            series = cls._make_series(None,
                                      gcal_id=shared_gcal_id,
                                      **series_data)

            # Update event_data with the parent series
            event_data['parent_series'] = series
            event_data['gcal_id'] = shared_gcal_id
            event_data['gcal_sequence'] = shared_gcal_sequence
            event_data['creator'] = shared_creator

            # Make the individual Event objects in the series
            while cls._more_events(series, date_data):
                ev = cls._make_event(event_data, date_data)
                series.events.append(ev)
                cls._increment_date_data(series, date_data)

            series.save()

        # Update the event in Google Calendar and publish it as necessary
        if move_to == cls.PUBLIC:
            response = gcal_client.publish_event(series.events[0])
        elif move_to == cls.PRIVATE:
            response = gcal_client.unpublish_event(series.events[0])
        response = gcal_client.update_event(series.events[0])

        # Return Google Calendar response
        return response