[ckan-dev] implimenting stream filters

Adrià Mercader adria.mercader at okfn.org
Fri Oct 11 16:32:24 UTC 2013


Hi Andrew,

If you want to do this server side it is really easy:

* Create a "templates" folder in your extension

* Register it using this on your plugin: plugins
toolkit.add_template_directory(config, 'templates')

* Copy this file [1] from CKAN core to the same path on your templates
directory (eg ckanext-geodatamn/ckanext/geodatamn/snippets/additional_info.html)

* Your local file should now be loaded instead of the core one, and
you can modify it to add some logic to tweak the labels.

[1] https://github.com/okfn/ckan/blob/master/ckan/templates/snippets/additional_info.html



On 9 October 2013 15:55, Koebrick, Andrew (MNIT)
<andrew.koebrick at state.mn.us> wrote:
> >> If you want to help marking the IGenshiStreamFilter interface a PR would be most welcomed :).
Sorry I missed some words here:
If you want to help marking the IGenshiStreamFilter interface *as
deprecated* a PR would be most welcomed

> I am very new to GitHub, and do not know what a PR is (Pull Request?) or how I would go about helping to update the documentation / sample extension.  But if anyone wants to walk me through the process (off list) I would be happy to contribute.  I will be digging deeper and deeper into this code as Minnesota builds out its CKAN instance and it would be great to be able to help improve the documentation as I find problems.

GitHub has some nice documentation on how to get started with Pull
Requests and contributing, you may want to have a look there:

https://help.github.com/articles/using-pull-requests


Best,

Adrià


>
> Cheers,
>
>
>
> Andrew
>
>
>
>
>
>
>
>
>
> From: ckan-dev-bounces at lists.okfn.org [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Adrià Mercader
> Sent: Friday, October 04, 2013 5:32 AM
>
>
> To: CKAN Development Discussions
> Subject: Re: [ckan-dev] implimenting stream filters
>
>
>
> Hi,
>
>
>
> Make sure to use the "latest" version of the CKAN docs (not sure how you got to the "ckan-docs-theme" one). Notice the version on the URL. There are links to docs to the different versions of CKAN in the lower right hand corner
>
>
>
> http://docs.ckan.org/en/latest/extensions/index.html
>
>
>
> If you want to help marking the IGenshiStreamFilter interface a PR would be most welcomed :). A notice in this docstring should suffice:
>
>
>
> https://github.com/okfn/ckan/blob/master/ckan/plugins/interfaces.py#L54
>
>
>
>
>
> Looking at the example looks like you already figured out how to fix it, but just in case, a custom template + a helper function is the way I would go.
>
>
>
> Hope this helps,
>
>
>
> Adrià
>
>
>
>
>
> On 3 October 2013 14:49, Stefan Oderbolz <stefan.oderbolz at liip.ch> wrote:
>
> No, I think this is the most up-to-date documentation. I'd suggest you have a look at the documentation about "Theming" if you want to change the frontend of CKAN (http://docs.ckan.org/en/ckan-docs-theme/theming.html).
>
>
>
> On Thu, Oct 3, 2013 at 3:13 PM, Koebrick, Andrew (MNIT) <andrew.koebrick at state.mn.us> wrote:
>
> Stefan,
>
>
>
> Thanks for the tips, I will play around.  I had thought that the Genshi was deprecated, but then saw it documented here:
>
> http://docs.ckan.org/en/ckan-docs-theme/writing-extensions.html#example-extension which is marked as “CKAN Documentation 2.2a documentation”.
>
>
> As I continue to get into the guts of the code, is there an accurate up-to-date location I can look to for documentation?
>
>
>
> Andrew
>
>
>
> From: ckan-dev-bounces at lists.okfn.org [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Stefan Oderbolz
> Sent: Thursday, October 03, 2013 2:34 AM
> To: CKAN Development Discussions
> Subject: Re: [ckan-dev] implimenting stream filters
>
>
>
> Hi Andrew,
>
>
>
> afaik IGenshiStreamFilter is deprecated and you shouldn't use it anymore.
>
>
>
> But there are several ways to achieve what you want. By default CKAN shows the key of each extra-fields as-is (you can find the code here: https://github.com/okfn/ckan/blob/master/ckan/templates/package/snippets/additional_info.html#L61).
>
>
>
> As you can see the displayed text is translated, so this would be one way to change the name that is displayed (e.g. you could specify "dsOriginator" should be translated to "Originator").
>
>
>
> Another way would be to override the "additional_info.html" template, so that for each displayed key the "ds" prefix is getting removed, something like
>
> <span scope="row" class="dataset-label" property="rdfs:label">{{ _(key)|replace('ds', '') }}</span>
>
>
>
> Note that this might fail if you have keys that contain "ds", a regex would be a better approach.
>
>
>
>
>
>
>
> On Wed, Oct 2, 2013 at 11:08 PM, Koebrick, Andrew (MNIT) <andrew.koebrick at state.mn.us> wrote:
>
> I am attempting to make an extension that customizes the output of some additional fields associated with datasets in our ckan setup.  For example, we have fields called “dsOriginator” which I would like to have displayed as just “Originator”.  I know the extension is at least partially functional since it is pulling our custom templates, but it does not seem to do the transform as expectedLive example at: http://devel.gisdata.mn.gov/dataset/base-2008-naip-airphotos-cir-wms
>
>
>
> I would be grateful for any pointers.
>
> ++++++++++++++++++++++++++++++++++++++++++
>
>
>
> from pylons import config
>
> from pylons import request
>
> from genshi.input import HTML
>
> from genshi.filters import Transformer
>
> from ckan.plugins import IGenshiStreamFilter
>
>
>
> import ckan.plugins as plugins
>
>
>
> class geodatamn(plugins.SingletonPlugin):
>
>    plugins.implements(plugins.IConfigurer, inherit=True)
>
>    plugins.implements(IGenshiStreamFilter, inherit=True)
>
>
>
>
>
>    def update_config(self, config):
>
>         plugins.toolkit.add_template_directory(config, 'templates')
>
>
>
>    def filter(self, stream):
>
>         """Update metadata field names to be human readable
>
>         """
>
>         stream = stream | Transformer('body').substitute('dsOriginator', 'Originator')
>
>
>
>         return stream
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
>
> Andrew Koebrick  |  MINNESOTA GEOSPATIAL INFORMATION OFFICE
>
> Web Coordinator / Systems administrator / Librarian
>
> MN.IT Services @ CENTRAL
>
> 651-201-2465 (w)  |   651-296-6398 (f) |  andrew.koebrick at state.mn.us
>
> 658 Cedar St., Room 300, St. Paul, MN 55155, www.mngeo.state.mn.us
>
> Information Technology for Minnesota Government   |   mn.gov/oet
>
>
>
>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
>
>
>
>
> --
>
> Liip AG  //  Feldstrasse 133 //  CH-8004 Zurich
> Tel +41 43 500 39 80 // GnuPG 0x7B588C67 // www.liip.ch
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
>
>
>
>
> --
>
> Liip AG  //  Feldstrasse 133 //  CH-8004 Zurich
> Tel +41 43 500 39 80 // GnuPG 0x7B588C67 // www.liip.ch
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>




More information about the ckan-dev mailing list