(self, sketch_id)
return self.to_json(updated_annotations,
                            status_code=HTTP_STATUS_CODE_OK)
Handles update request to annotations (currently only comments are
            supported).

        Args:
            sketch_id: Integer primary key for a sketch database model

        Returns:
            The updated annotation object in JSON (instance of
            flask.wrappers.Response)
Handles update request to annotations (currently only comments are
            supported).
Handles update request to annotations ( currently only comments are supported ) .
def put(self, sketch_id):
        """Handles update request to annotations (currently only comments are
            supported).

        Args:
            sketch_id: Integer primary key for a sketch database model

        Returns:
            The updated annotation object in JSON (instance of
            flask.wrappers.Response)
        """

        form = forms.EventAnnotationForm.build(request)
        if not form.validate_on_submit():
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST, 'Unable to validate form data.')

        updated_annotations = []
        sketch = self._get_sketch(sketch_id)

        indices = [
            t.searchindex.index_name for t in sketch.timelines
            if t.get_status.status.lower() == 'ready']

        # Retriving events list submitted in the request
        events = form.events.raw_data

        # Loop through all events supplied and update the annotation on each
        # event with the supplied annotation value.
        # Currently the UI does not support mass comments update, so typically
        # only one event will be in the event list
        for _event in events:
            searchindex_id = _event['_index']
            searchindex = SearchIndex.query.filter_by(
                index_name=searchindex_id).first()
            event_id = _event['_id']

            if searchindex_id not in indices:
                abort(
                    HTTP_STATUS_CODE_BAD_REQUEST,
                    'Search index ID ({0!s}) does not belong to the list '
                    'of indices'.format(searchindex_id))

            # Retrive the event from the SQL database based on the event_id
            # supplied in the request
            event = Event.query.filter_by(
                sketch=sketch, searchindex=searchindex,
                document_id=event_id).first()

            if not event:
                abort(
                    HTTP_STATUS_CODE_NOT_FOUND, 'No event found with the id: '
                    '{0!s}'.format(event_id))

            # Retrive annotation type supplied in the request
            annotation_type = form.annotation_type.data
            # Retrive the modified annotation supplied in the request
            annotation = form.annotation.data

            if 'comment' in annotation_type:
                # Retrive the comment attached to the event bases on the comment
                # id supplied in the request
                comment = event.get_comment(annotation['id'])
                if not comment:
                    abort(HTTP_STATUS_CODE_NOT_FOUND, 'No comment found with '
                          'this id: {0!d}.'.format(annotation['id']))

                # Make sure the current user is the owner of the comment
                if comment.user != current_user:
                    abort(HTTP_STATUS_CODE_FORBIDDEN,
                          'User is not owner of the comment.')

                # Update the comment with the new value
                annotation = event.update_comment(annotation['id'],
                                                  annotation['comment'])

                if not annotation:
                    abort(
                        HTTP_STATUS_CODE_BAD_REQUEST,
                        'Update operation unsuccessful')

                updated_annotations.append(annotation)
            else:
                abort(
                    HTTP_STATUS_CODE_BAD_REQUEST,
                    'Annotation type needs to be a comment, '
                    'not {0!s}'.format(annotation_type))

        return self.to_json(updated_annotations,
                            status_code=HTTP_STATUS_CODE_OK)
def put ( self , sketch_id ) : form = forms . EventAnnotationForm . build ( request ) if not form . validate_on_submit ( ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Unable to validate form data.' ) updated_annotations = [ ] sketch = self . _get_sketch ( sketch_id ) indices = [ t . searchindex . index_name for t in sketch . timelines if t . get_status . status . lower ( ) == 'ready' ] # Retriving events list submitted in the request events = form . events . raw_data # Loop through all events supplied and update the annotation on each # event with the supplied annotation value. # Currently the UI does not support mass comments update, so typically # only one event will be in the event list for _event in events : searchindex_id = _event [ '_index' ] searchindex = SearchIndex . query . filter_by ( index_name = searchindex_id ) . first ( ) event_id = _event [ '_id' ] if searchindex_id not in indices : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Search index ID ({0!s}) does not belong to the list ' 'of indices' . format ( searchindex_id ) ) # Retrive the event from the SQL database based on the event_id # supplied in the request event = Event . query . filter_by ( sketch = sketch , searchindex = searchindex , document_id = event_id ) . first ( ) if not event : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No event found with the id: ' '{0!s}' . format ( event_id ) ) # Retrive annotation type supplied in the request annotation_type = form . annotation_type . data # Retrive the modified annotation supplied in the request annotation = form . annotation . data if 'comment' in annotation_type : # Retrive the comment attached to the event bases on the comment # id supplied in the request comment = event . get_comment ( annotation [ 'id' ] ) if not comment : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No comment found with ' 'this id: {0!d}.' . format ( annotation [ 'id' ] ) ) # Make sure the current user is the owner of the comment if comment . user != current_user : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'User is not owner of the comment.' ) # Update the comment with the new value annotation = event . update_comment ( annotation [ 'id' ] , annotation [ 'comment' ] ) if not annotation : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Update operation unsuccessful' ) updated_annotations . append ( annotation ) else : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Annotation type needs to be a comment, ' 'not {0!s}' . format ( annotation_type ) ) return self . to_json ( updated_annotations , status_code = HTTP_STATUS_CODE_OK )