(self)
return self.to_json(
            searchindex, status_code=HTTP_STATUS_CODE_CREATED)
Handles POST request to the resource.

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

        Returns:
            A view in JSON (instance of flask.wrappers.Response)
        """
        upload_enabled = current_app.config['UPLOAD_ENABLED']
        if not upload_enabled:
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Failed to create timeline, upload not enabled')

        form = forms.CreateTimelineForm()
        if not form.validate_on_submit():
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Failed to create timeline, form data not validated')

        sketch_id = form.sketch_id.data
        timeline_name = form.name.data

        sketch = None
        if 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.')

        # We do not need a human readable filename or
        # datastore index name, so we use UUIDs here.
        index_name = uuid.uuid4().hex
        if not isinstance(index_name, six.text_type):
            index_name = codecs.decode(index_name, 'utf-8')

        # Create the search index in the Timesketch database
        searchindex = SearchIndex.get_or_create(
            name=timeline_name,
            description=timeline_name,
            user=current_user,
            index_name=index_name)
        searchindex.grant_permission(permission='read', user=current_user)
        searchindex.grant_permission(permission='write', user=current_user)
        searchindex.grant_permission(
            permission='delete', user=current_user)
        searchindex.set_status('processing')
        db_session.add(searchindex)
        db_session.commit()

        timeline = None
        if sketch and sketch.has_permission(current_user, 'write'):
            timeline = Timeline(
                name=searchindex.name,
                description=searchindex.description,
                sketch=sketch,
                user=current_user,
                searchindex=searchindex)
            sketch.timelines.append(timeline)
            db_session.add(timeline)
            db_session.commit()

        # Return Timeline if it was created.
        # pylint: disable=no-else-return
        if timeline:
            return self.to_json(
                timeline, status_code=HTTP_STATUS_CODE_CREATED)

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

        return self.to_json(
            searchindex, status_code=HTTP_STATUS_CODE_CREATED)
def post ( self ) : upload_enabled = current_app . config [ 'UPLOAD_ENABLED' ] if not upload_enabled : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Failed to create timeline, upload not enabled' ) form = forms . CreateTimelineForm ( ) if not form . validate_on_submit ( ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Failed to create timeline, form data not validated' ) sketch_id = form . sketch_id . data timeline_name = form . name . data sketch = None if 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.' ) # We do not need a human readable filename or # datastore index name, so we use UUIDs here. index_name = uuid . uuid4 ( ) . hex if not isinstance ( index_name , six . text_type ) : index_name = codecs . decode ( index_name , 'utf-8' ) # Create the search index in the Timesketch database searchindex = SearchIndex . get_or_create ( name = timeline_name , description = timeline_name , user = current_user , index_name = index_name ) searchindex . grant_permission ( permission = 'read' , user = current_user ) searchindex . grant_permission ( permission = 'write' , user = current_user ) searchindex . grant_permission ( permission = 'delete' , user = current_user ) searchindex . set_status ( 'processing' ) db_session . add ( searchindex ) db_session . commit ( ) timeline = None if sketch and sketch . has_permission ( current_user , 'write' ) : timeline = Timeline ( name = searchindex . name , description = searchindex . description , sketch = sketch , user = current_user , searchindex = searchindex ) sketch . timelines . append ( timeline ) db_session . add ( timeline ) db_session . commit ( ) # Return Timeline if it was created. # pylint: disable=no-else-return if timeline : return self . to_json ( timeline , status_code = HTTP_STATUS_CODE_CREATED ) # Update the last activity of a sketch. utils . update_sketch_last_activity ( sketch ) return self . to_json ( searchindex , status_code = HTTP_STATUS_CODE_CREATED )