Package: ckanext-toolbelt
ckanext-toolbeltCollection of different tools for daily use.RequirementsCKAN versionCompatible?2.9yes2.10yesmasteryesContentDecoratorsCollectorCachePluginsCLIMiscDecorators (ckanext.toolbelt.decorators)CollectorCreates a decorator that collects functions and returns them in a
dictionary. Originally designed for actions, auth functions, validators and
helpers.:information_source: CKAN v2.10 hastk.blanketmodule. It does the same
things in a bit different manner.Can be used as decorator. CallCollector.get_collectionwhen you need
dictionary with names of helpers mapped to helper functionshelper = Collector()

@helper
def func():
	pass

###
# ITemplateHelpers
def get_helpers(self):
	return helper.get_collection()Collector.splitallows you to visually separate decorator from the method,
that returns collectionaction, get_actions = Collector().split()

@action
def func():
	pass

###
# IActions
def get_actions(self):
	return get_actions()If you want your functions prefixed by the plugin name, provide this prefix as
a first argument to theCollector's constructor. If particular items must
remain unprefixed, you can specify what name to use, when decorating an itemvalidator, get_validators = Collector("toolbelt").split()

@validator
def func():
	"""I am toolbelt_func
	"""
	pass

@validator("custom_func")
def func():
	"""I am custom_func
	"""
	pass

###
# IValidators
def get_validators(self):
	return get_validators()Back to contentCacheCache for functions.Cache()
def func(v):
    return v * vBy default, cache is based on:module, where function is definedname of the functionpositional argumentsnamed argumentsThat means that following two invocations cached separately:func(10)
func(v=10)Cached data stored in redis as a JSON serialized structure. In order to use
different serializers, you can specifydumperandloaderparameters when
creatingCacheinstance. Any function that accepts single value and returnsstrorbytescan be used as adumper. Any function that acceptsstrorbytesand returns unserialized value can be used as loader.from pickle import dumps, loads

@Cache(dumper=dumps, loader=loads)
def func(v):
    return vAs mentioned before, cache key computed using module, name of the function and
parameters. It can be changed by passing a function askeyargument to theCacheconstructor. Expected signature iskey_strategy(func, *args, **kwargs).# this function will be called only once, because cache key is based on its name.
# And name will never change. Unless you change it
@Cache(key=lambda f, *a, **k: f.__name__)
def func(v):
    return vCache duration(in seconds) can be configured viadurationparameter of the
constructor(which can be a callable that returns comuted duration).cache = Cache(duration=3600)

@cache
def func(v):
    return v + vBack to contentPluginstoolbelt_fdt_sqlalchemyAdapter forFlask-SQLAlchemy. Enables
SQLAlchemy panel on FlaskDebugToolbar. You have to installflask-sqlalchemyextra to use this plugin:pipinstall'ckanext-toolbelt[flask-sqlalchemy]'toolbelt_cascade_organization_updatesReindex all organization's datasets when organization updated. Requires
background worker.toolbelt_composite_groups/toolbelt_composite_organizationsEnable repeating subfields(ckanext-scheming) for organization and group schemasBack to contentCLIAs soon as you've installed ckanext-toolbelt, it will registerckan toolbeltroute for CLI. You don't have to addtoolbeltto the list of enabled
plugins.Depending on the active plugins, extra subroutes may be added to theckan toolbeltroute.In addition, there is globalctbcommand that allows to use this package
without CKAN installed or without CKAN config file. But in this way some of
commands (search-indexfor example) are not available, because they use CKAN
core.ctbalias exists for setting up the CKAN or extensions and running
generic services, that do not rely on CKAN instance.Global commands, available viactbandckan toolbeltroutes:# create a generic configuration. Supported types:# * deps-makefile  CKAN dependency manager# * pre-commit     Pre-commit# * pyproject      pyproject.toml# * gulp-sass      gulpfile.js with SASS configurationmakeconfig<type># create a configuration for GitHub Action. Supported types:# * pypi-publish    Publish package to PyPI when vX.Y.Z tag added.# * release-please  Create a PR that compiles changelog and publishes GitHub release.# * test            Test workflow.makegh-action<type># Generate parts of README.md# Supported types:# * config  Print declared config options for the given plugins.makereadme<type># Start mail server that will catch outcomming mails.devmail-serverCommands that depends on CKAN core and available only viackan toolbeltroute:# Drop packages that are only in search index but not in DB.search-indexclear-missing# Clean the DB, optionally keeping data in the given tables.dbclean--yes[-kuser][-kgroup][-k...]Back to contentMiscckanext.toolbelt.utils.cacheDontCacheCacheckanext.toolbelt.utils.fsStaticPathNo-op wrapper around filepath that can be used as a context manager:withStaticPath("/tmp/x.txt")aspath:withopen(path)assrc:...# nothing is changedRemovablePathContext manager that removes file on exit:withRemovablePath("/tmp/x.txt")aspath:withopen(path)assrc:...# /tmp/x.txt is removedpath_to_resource(res_dict, max_size=0)Returns a filepath for a resource.If resource is stored locally, return StaticPath. If resource stored remotely,
download it to /tmp and return RemovablePath. Remote resources with size
exceedingmax_sizeare not downloaded and empty StaticPath returned.Example:withpath_to_resource(resource)aspath:withopen(path)assrc:print(src.read())ckanext.toolbelt.utils.schemingget_validation_schemackanext.toolbelt.utils.structuresNodeckanext.toolbelt.utils.hierarchyNodeStrategyParentReferencepackage_hierarchyBack to content