(self, sketch_id)
return (HTTP_STATUS_CODE_BAD_REQUEST, 'Could not delete the annotation'
                ' type {0!s} with the id {1!d}'
                .format(annotation_type, annotation_id))
Handles delete request of annotations (currently only comments are
            supported).

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

        Returns:
            A HTTP 200 if the annotation was successfully deleted and HTTP 400
            otherwise
Handles delete request of annotations (currently only comments are
            supported).
Handles delete request of annotations ( currently only comments are supported ) .
def delete(self, sketch_id):
        """Handles delete request of annotations (currently only comments are
            supported).

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

        Returns:
            A HTTP 200 if the annotation was successfully deleted and HTTP 400
            otherwise
        """

        # Retrive request arguments
        args = self.parser.parse_args()
        annotation_type = args.get('annotation_type')
        annotation_id = args.get('annotation_id')
        event_id = args.get('event_id')
        searchindex_id = args.get('searchindex_id')
        event_type = args.get('event_type')

        sketch = self._get_sketch(sketch_id)

        current_search_node = None
        _search_node_id = args.get('currentSearchNode_id')
        if _search_node_id:
            current_search_node = self._get_current_search_node(_search_node_id,
                                                                sketch)
        searchindex = SearchIndex.query.filter_by(
            index_name=searchindex_id).first()

        # 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))

        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.')

            if event.remove_comment(annotation_id):
                # Remove label __ts_comment if the event has no more comments
                if len(event.comments) < 1:
                    self.datastore.set_label(
                        searchindex_id,
                        event_id,
                        event_type,
                        sketch.id,
                        current_user.id,
                        '__ts_comment',
                        toggle=True
                    )
                    if current_search_node:
                        current_search_node.remove_label('__ts_comment')

                return HTTP_STATUS_CODE_OK

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

        return (HTTP_STATUS_CODE_BAD_REQUEST, 'Could not delete the annotation'
                ' type {0!s} with the id {1!d}'
                .format(annotation_type, annotation_id))
def delete ( self , sketch_id ) : # Retrive request arguments args = self . parser . parse_args ( ) annotation_type = args . get ( 'annotation_type' ) annotation_id = args . get ( 'annotation_id' ) event_id = args . get ( 'event_id' ) searchindex_id = args . get ( 'searchindex_id' ) event_type = args . get ( 'event_type' ) sketch = self . _get_sketch ( sketch_id ) current_search_node = None _search_node_id = args . get ( 'currentSearchNode_id' ) if _search_node_id : current_search_node = self . _get_current_search_node ( _search_node_id , sketch ) searchindex = SearchIndex . query . filter_by ( index_name = searchindex_id ) . first ( ) # 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 ) ) 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.' ) if event . remove_comment ( annotation_id ) : # Remove label __ts_comment if the event has no more comments if len ( event . comments ) < 1 : self . datastore . set_label ( searchindex_id , event_id , event_type , sketch . id , current_user . id , '__ts_comment' , toggle = True ) if current_search_node : current_search_node . remove_label ( '__ts_comment' ) return HTTP_STATUS_CODE_OK else : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Annotation type needs to be a comment, ' 'not {0!s}' . format ( annotation_type ) ) return ( HTTP_STATUS_CODE_BAD_REQUEST , 'Could not delete the annotation' ' type {0!s} with the id {1!d}' . format ( annotation_type , annotation_id ) )