def before_update_object(self, event_topic, data, view_kwargs):
        """
        method to save image urls before updating event object
        :param event_topic:
        :param data:
        :param view_kwargs:
        :return:
        """
        if data.get('system_image_url'):
            try:
                uploaded_image = create_system_image(data['system_image_url'], unique_identifier=event_topic.id)
            except (urllib.error.HTTPError, urllib.error.URLError):
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'}, 'Invalid Image URL'
                )
            except IOError:
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'}, 'Image is absent at URL'
                )
        else:
            try:
                uploaded_image = create_system_image(unique_identifier=event_topic.id)
            except IOError:
                raise UnprocessableEntity(
                    {'source': ''}, 'Default Image is absent in server'
                )

            data['system_image_url'] = uploaded_image['system_image_url']
예제 #2
0
    def after_create_object(self, event_topic, data, view_kwargs):
        """
        after create method to save roles for users and add the user as an accepted role(organizer)
        :param event_topic:
        :param data:
        :param view_kwargs:
        :return:
        """
        if data.get('system_image_url'):
            try:
                uploaded_image = create_system_image(
                    data['system_image_url'], unique_identifier=event_topic.id)
            except (urllib.error.HTTPError, urllib.error.URLError):
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'},
                    'Invalid Image URL')
            except IOError:
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'},
                    'Image is absent at URL')
        else:
            try:
                uploaded_image = create_system_image(
                    unique_identifier=event_topic.id)
            except IOError:
                raise UnprocessableEntity({'source': ''},
                                          'Default Image is absent in server')

        self.session.query(EventTopic).filter_by(
            id=event_topic.id).update(uploaded_image)
        self.session.commit()
    def after_create_object(self, event_topic, data, view_kwargs):
        """
        after create method to save roles for users and add the user as an accepted role(organizer)
        :param event_topic:
        :param data:
        :param view_kwargs:
        :return:
        """
        if data.get('system_image_url'):
            try:
                uploaded_image = create_system_image(data['system_image_url'], unique_identifier=event_topic.id)
            except (urllib.error.HTTPError, urllib.error.URLError):
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'}, 'Invalid Image URL'
                )
            except IOError:
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'}, 'Image is absent at URL'
                )
        else:
            try:
                uploaded_image = create_system_image(unique_identifier=event_topic.id)
            except IOError:
                raise UnprocessableEntity(
                    {'source': ''}, 'Default Image is absent in server'
                )

        self.session.query(EventTopic).filter_by(id=event_topic.id).update(uploaded_image)
        self.session.commit()
예제 #4
0
    def before_update_object(self, event_topic, data, view_kwargs):
        """
        method to save image urls before updating event object
        :param event_topic:
        :param data:
        :param view_kwargs:
        :return:
        """
        if data.get('system_image_url'):
            try:
                uploaded_image = create_system_image(
                    data['system_image_url'], unique_identifier=event_topic.id)
            except (urllib.error.HTTPError, urllib.error.URLError):
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'},
                    'Invalid Image URL')
            except IOError:
                raise UnprocessableEntity(
                    {'source': 'attributes/system-image-url'},
                    'Image is absent at URL')
        else:
            try:
                uploaded_image = create_system_image(
                    unique_identifier=event_topic.id)
            except IOError:
                raise UnprocessableEntity({'source': ''},
                                          'Default Image is absent in server')

            data['system_image_url'] = uploaded_image['system_image_url']