[ckan-dev] plugins.toolkit

Toby Dacre toby.okfn at gmail.com
Thu Apr 19 11:11:33 UTC 2012


Hi,

As part of the general cleanup I've created a new file plugins/toolkit.py
to make a stable set of functions/objects available to plugins.  Please let
me know if there are other functions/objects that would be helpful or any
people think should not be here.

__all__ = [
    ## Imported functions ##
    'c',                    # template context
    'request',              # http request object
    'render',               # template render function
    'render_text',          # Genshi NewTextTemplate render function
    'render_snippet',       # snippet render function
    'asbool',               # converts an object to a boolean
    'asint',                # converts an object to an integer
    'aslist',               # converts an object to a list
    'literal',              # stop tags in a string being escaped

    ## Functions fully defined here ##
    'add_template_directory',
    'add_public_directory',
]

the last two functions are helpers to add extra dirs.  This just removes
the need for common boilerplate in plugins

an example extension plugin.py for the soon to be released ckanext-datahub

import ckan.plugins as p

class DataHub(p.SingletonPlugin):
    p.implements(p.IConfigurer)

    def update_config(self, config):
        p.toolkit.add_template_directory(config, 'templates')
        p.toolkit.add_public_directory(config, 'public')

Using these functions will mean that the plugin will require ckan 1.7 so
there is no rush to change our existing plugins but it would be good if new
plugins can start using this.

@Ross - I've added a render_text() helper for NewTextTemplates as requested.

Toby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20120419/b46d379a/attachment.html>


More information about the ckan-dev mailing list