Esempio n. 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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 8
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