(self)
return self.to_json(searchtemplate)
Handles POST request to the resource.

        Returns:
            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:
            View in JSON (instance of flask.wrappers.Response)
        """
        form = request.json
        if not form:
            form = request.data

        search_id = form.get('search_id')
        if not search_id:
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Unable to save the searchtemplate, the saved search ID is '
                'missing.')

        search_obj = View.query.get(search_id)
        if not search_obj:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND, 'No search found with this ID.')

        templates = SearchTemplate.query.filter_by(
            name=search_obj.name,
            description=search_obj.description).all()

        if templates:
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'This search has already been saved as a template.')

        sketch = Sketch.query.get_with_acl(search_obj.sketch.id)
        if not sketch:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.')

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

        if sketch.get_status.status == 'archived':
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Unable to query on an archived sketch.')

        # Remove date filter chips from the saved search.
        query_filter_dict = json.loads(search_obj.query_filter)
        chips = []
        for chip in query_filter_dict.get('chips', []):
            chip_type = chip.get('type', '')
            if not chip_type.startswith('datetime'):
                chips.append(chip)

        query_filter_dict['chips'] = chips
        query_filter = json.dumps(query_filter_dict, ensure_ascii=False)

        searchtemplate = SearchTemplate(
            name=search_obj.name,
            description=search_obj.description,
            user=current_user,
            query_string=search_obj.query_string,
            query_filter=query_filter,
            query_dsl=search_obj.query_dsl)

        db_session.add(searchtemplate)
        db_session.commit()

        search_obj.searchtemplate = searchtemplate
        db_session.add(search_obj)
        db_session.commit()

        return self.to_json(searchtemplate)
def post ( self ) : form = request . json if not form : form = request . data search_id = form . get ( 'search_id' ) if not search_id : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Unable to save the searchtemplate, the saved search ID is ' 'missing.' ) search_obj = View . query . get ( search_id ) if not search_obj : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No search found with this ID.' ) templates = SearchTemplate . query . filter_by ( name = search_obj . name , description = search_obj . description ) . all ( ) if templates : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'This search has already been saved as a template.' ) sketch = Sketch . query . get_with_acl ( search_obj . sketch . id ) if not sketch : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch found with this ID.' ) if not sketch . has_permission ( current_user , 'read' ) : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'User does not have read access controls on sketch.' ) if sketch . get_status . status == 'archived' : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Unable to query on an archived sketch.' ) # Remove date filter chips from the saved search. query_filter_dict = json . loads ( search_obj . query_filter ) chips = [ ] for chip in query_filter_dict . get ( 'chips' , [ ] ) : chip_type = chip . get ( 'type' , '' ) if not chip_type . startswith ( 'datetime' ) : chips . append ( chip ) query_filter_dict [ 'chips' ] = chips query_filter = json . dumps ( query_filter_dict , ensure_ascii = False ) searchtemplate = SearchTemplate ( name = search_obj . name , description = search_obj . description , user = current_user , query_string = search_obj . query_string , query_filter = query_filter , query_dsl = search_obj . query_dsl ) db_session . add ( searchtemplate ) db_session . commit ( ) search_obj . searchtemplate = searchtemplate db_session . add ( search_obj ) db_session . commit ( ) return self . to_json ( searchtemplate )