[ckan-dev] plugins.toolkit
Toby Dacre
toby.okfn at gmail.com
Fri Apr 20 11:56:29 UTC 2012
Update:
to solve issues with circular imports I've changed the implementation of
the toolkit to be an object. It still works in an identical way
eg
<my_plugin.py>
import ckan.plugins as p
p.toolkit.function_or_object
Toby
On 19 April 2012 16:04, Toby Dacre <toby.okfn at gmail.com> wrote:
>
>
> On 19 April 2012 15:59, Ross Jones <ross.jones at okfn.org> wrote:
>
>> Doesn't NotFound mean object not found rather than action not found?
>>
>> logic/__init__.py
>
> class NotFound(ActionError):
> pass
>
> says just actions to me
>
> Toby
>
> Ross
>>
>> On 19 Apr 2012, at 15:53, Toby Dacre wrote:
>>
>> 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
>>>
>>>
>>>
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> http://lists.okfn.org/mailman/listinfo/ckan-dev
>>
>>
>>
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> http://lists.okfn.org/mailman/listinfo/ckan-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20120420/cec9f40a/attachment-0001.html>
More information about the ckan-dev
mailing list