(self)
return f'Saved search as a template to ID: {self.id}'
Save the search template.
Save the search template.
Save the search template .
def save(self):
        """Save the search template."""
        if self._resource_id:
            raise ValueError(
                'The template has already been saved, ATM updates to an '
                'existing template are not yet supported.')

        if not self._search_id:
            raise ValueError(
                'Unable to save the search template since the identification '
                'value of the saved search is not known. The object needs '
                'to be initialized from a previously saved search.')

        data = {
            'search_id': self._search_id,
        }
        resource_url = f'{self.api.api_root}/searchtemplate/'
        response = self.api.session.post(resource_url, json=data)

        status = error.check_return_status(response, logger)
        if not status:
            error.error_message(
                response, 'Unable to save search as a template',
                error=RuntimeError)

        response_json = error.get_response_json(response, logger)
        template_dict = response_json.get('objects', [{}])[0]

        self._resource_id = template_dict.get('id', 0)
        self.resource_uri = f'searchtemplate/{self._resource_id}/'
        return f'Saved search as a template to ID: {self.id}'
def save ( self ) : if self . _resource_id : raise ValueError ( 'The template has already been saved, ATM updates to an ' 'existing template are not yet supported.' ) if not self . _search_id : raise ValueError ( 'Unable to save the search template since the identification ' 'value of the saved search is not known. The object needs ' 'to be initialized from a previously saved search.' ) data = { 'search_id' : self . _search_id , } resource_url = f'{self.api.api_root}/searchtemplate/' response = self . api . session . post ( resource_url , json = data ) status = error . check_return_status ( response , logger ) if not status : error . error_message ( response , 'Unable to save search as a template' , error = RuntimeError ) response_json = error . get_response_json ( response , logger ) template_dict = response_json . get ( 'objects' , [ { } ] ) [ 0 ] self . _resource_id = template_dict . get ( 'id' , 0 ) self . resource_uri = f'searchtemplate/{self._resource_id}/' return f'Saved search as a template to ID: {self.id}'