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

        Returns:
            A search index 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 search index in JSON (instance of flask.wrappers.Response)
        """
        form = forms.SearchIndexForm.build(request)
        searchindex_name = form.searchindex_name.data
        es_index_name = form.es_index_name.data
        public = form.public.data

        if not form.validate_on_submit():
            abort(HTTP_STATUS_CODE_BAD_REQUEST, 'Unable to validate form data')

        searchindex = SearchIndex.query.filter_by(
            index_name=es_index_name).first()
        metadata = {'created': True}

        if searchindex:
            metadata['created'] = False
            metadata['deleted'] = searchindex.get_status.status == 'deleted'
            status_code = HTTP_STATUS_CODE_OK
        else:
            searchindex = SearchIndex.get_or_create(
                name=searchindex_name,
                description=searchindex_name,
                user=current_user,
                index_name=es_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)

            if public:
                searchindex.grant_permission(permission='read', user=None)

            datastore = self.datastore

            if not datastore.client.indices.exists(index=es_index_name):
                self.datastore.create_index(
                    index_name=es_index_name, doc_type='generic_event')

            db_session.add(searchindex)
            db_session.commit()
            status_code = HTTP_STATUS_CODE_CREATED

        return self.to_json(
            searchindex, meta=metadata, status_code=status_code)
def post ( self ) : form = forms . SearchIndexForm . build ( request ) searchindex_name = form . searchindex_name . data es_index_name = form . es_index_name . data public = form . public . data if not form . validate_on_submit ( ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Unable to validate form data' ) searchindex = SearchIndex . query . filter_by ( index_name = es_index_name ) . first ( ) metadata = { 'created' : True } if searchindex : metadata [ 'created' ] = False metadata [ 'deleted' ] = searchindex . get_status . status == 'deleted' status_code = HTTP_STATUS_CODE_OK else : searchindex = SearchIndex . get_or_create ( name = searchindex_name , description = searchindex_name , user = current_user , index_name = es_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 ) if public : searchindex . grant_permission ( permission = 'read' , user = None ) datastore = self . datastore if not datastore . client . indices . exists ( index = es_index_name ) : self . datastore . create_index ( index_name = es_index_name , doc_type = 'generic_event' ) db_session . add ( searchindex ) db_session . commit ( ) status_code = HTTP_STATUS_CODE_CREATED return self . to_json ( searchindex , meta = metadata , status_code = status_code )