def wrapper(klass): resource_name = klass.__name__.lower() params = dict(collection_path='/{0}s'.format(resource_name), path='/{0}s/{{id}}'.format(resource_name), description='Collection of {0}'.format(resource_name), error_handler=json_error_handler, cors_origins=('*',), depth=2) params.update(**kwargs) return resource.resource(**params)(klass)
def cms_resource(resource_name, **kwargs): """ A helper that returns a cornice @resource decorator, pre-populating the collection_path, path, and name from the resource_name argument. :param resource_name: Name of the resource :return: @resource decorator """ list_url = '/api/' + resource_name detail_url = list_url + '/{id}' return resource( name=resource_name, collection_path=list_url, path=detail_url, acl=get_global_acls, **kwargs )
def rest_resource(model): collection_path = model.collection_path() return resource(collection_path=collection_path, path='%s/{id}' % collection_path, factory=id_factory(model))