(self, sketch_id)
return self.to_json(
            timeline, meta=metadata, status_code=return_code)
Handles POST request to the resource.

        Returns:
            A sketch in JSON (instance of flask.wrappers.Response)
Handles POST request to the resource.
Handles POST request to the resource .
def post(self, sketch_id):
        """Handles POST request to the resource.

        Returns:
            A sketch in JSON (instance of flask.wrappers.Response)
        """
        sketch = Sketch.query.get_with_acl(sketch_id)
        if not sketch:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.')

        if not sketch.has_permission(current_user, 'write'):
            abort(HTTP_STATUS_CODE_FORBIDDEN,
                  'User does not have write access controls on sketch.')

        form = request.json
        if not form:
            form = request.data

        metadata = {'created': True}

        searchindex_id = form.get('timeline', 0)
        if isinstance(searchindex_id, str) and searchindex_id.isdigit():
            searchindex_id = int(searchindex_id)

        if not isinstance(searchindex_id, int):
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'The timeline (searchindex id) needs to be an integer.')

        searchindex = SearchIndex.query.get_with_acl(searchindex_id)
        if searchindex.get_status.status == 'deleted':
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Unable to create a timeline using a deleted search index')

        timeline_id = [
            t.searchindex.id for t in sketch.timelines
            if t.searchindex.id == searchindex_id
        ]

        if not timeline_id:
            return_code = HTTP_STATUS_CODE_CREATED
            timeline_name = form.get('timeline_name', searchindex.name)
            timeline = Timeline(
                name=timeline_name,
                description=searchindex.description,
                sketch=sketch,
                user=current_user,
                searchindex=searchindex)
            sketch.timelines.append(timeline)
            labels_to_prevent_deletion = current_app.config.get(
                'LABELS_TO_PREVENT_DELETION', [])

            for label in sketch.get_labels:
                if label not in labels_to_prevent_deletion:
                    continue
                timeline.add_label(label)
                searchindex.add_label(label)

            # Set status to ready so the timeline can be queried.
            timeline.set_status('ready')

            db_session.add(timeline)
            db_session.commit()
        else:
            metadata['created'] = False
            return_code = HTTP_STATUS_CODE_OK
            timeline = Timeline.query.get(timeline_id)

        # Run sketch analyzers when timeline is added. Import here to avoid
        # circular imports.
        # pylint: disable=import-outside-toplevel
        if current_app.config.get('AUTO_SKETCH_ANALYZERS'):
            # pylint: disable=import-outside-toplevel
            from timesketch.lib import tasks
            sketch_analyzer_group, _ = tasks.build_sketch_analysis_pipeline(
                sketch_id, searchindex_id, current_user.id,
                timeline_id=timeline_id)
            if sketch_analyzer_group:
                pipeline = (tasks.run_sketch_init.s(
                    [searchindex.index_name]) | sketch_analyzer_group)
                pipeline.apply_async()

        # Update the last activity of a sketch.
        utils.update_sketch_last_activity(sketch)

        return self.to_json(
            timeline, meta=metadata, status_code=return_code)
def post ( self , sketch_id ) : sketch = Sketch . query . get_with_acl ( sketch_id ) if not sketch : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch found with this ID.' ) if not sketch . has_permission ( current_user , 'write' ) : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'User does not have write access controls on sketch.' ) form = request . json if not form : form = request . data metadata = { 'created' : True } searchindex_id = form . get ( 'timeline' , 0 ) if isinstance ( searchindex_id , str ) and searchindex_id . isdigit ( ) : searchindex_id = int ( searchindex_id ) if not isinstance ( searchindex_id , int ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'The timeline (searchindex id) needs to be an integer.' ) searchindex = SearchIndex . query . get_with_acl ( searchindex_id ) if searchindex . get_status . status == 'deleted' : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Unable to create a timeline using a deleted search index' ) timeline_id = [ t . searchindex . id for t in sketch . timelines if t . searchindex . id == searchindex_id ] if not timeline_id : return_code = HTTP_STATUS_CODE_CREATED timeline_name = form . get ( 'timeline_name' , searchindex . name ) timeline = Timeline ( name = timeline_name , description = searchindex . description , sketch = sketch , user = current_user , searchindex = searchindex ) sketch . timelines . append ( timeline ) labels_to_prevent_deletion = current_app . config . get ( 'LABELS_TO_PREVENT_DELETION' , [ ] ) for label in sketch . get_labels : if label not in labels_to_prevent_deletion : continue timeline . add_label ( label ) searchindex . add_label ( label ) # Set status to ready so the timeline can be queried. timeline . set_status ( 'ready' ) db_session . add ( timeline ) db_session . commit ( ) else : metadata [ 'created' ] = False return_code = HTTP_STATUS_CODE_OK timeline = Timeline . query . get ( timeline_id ) # Run sketch analyzers when timeline is added. Import here to avoid # circular imports. # pylint: disable=import-outside-toplevel if current_app . config . get ( 'AUTO_SKETCH_ANALYZERS' ) : # pylint: disable=import-outside-toplevel from timesketch . lib import tasks sketch_analyzer_group , _ = tasks . build_sketch_analysis_pipeline ( sketch_id , searchindex_id , current_user . id , timeline_id = timeline_id ) if sketch_analyzer_group : pipeline = ( tasks . run_sketch_init . s ( [ searchindex . index_name ] ) | sketch_analyzer_group ) pipeline . apply_async ( ) # Update the last activity of a sketch. utils . update_sketch_last_activity ( sketch ) return self . to_json ( timeline , meta = metadata , status_code = return_code )