[ckan-dev] plugins.toolkit

Toby Dacre toby.okfn at gmail.com
Thu Apr 19 14:53:51 UTC 2012


After looking at the ecportal and dgu extensions I've added these functions


    '_',                    # i18n translation
    'get_action',           # get logic action function
    'check_access',         # check logic function authorisation
    'NotFound',             # action not found exception
    'NotAuthorized',        # action not authorized exception
    'ValidationError',      # model update validation error
    'CkanCommand',          # class for providing cli interfaces

I think it might be an idea to change NotFound to ActionNotFound any
objections?

To make things easier regarding transitioning of plugins I've added a
couple of extra functions and an exception

    'requires_ckan_version',
    'check_ckan_version',
    'CkanVersionException',



On 19 April 2012 12:11, Toby Dacre <toby.okfn at gmail.com> wrote:

> 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/da190b10/attachment-0001.html>


More information about the ckan-dev mailing list