[ckan-dev] implimenting stream filters

Stefan Oderbolz stefan.oderbolz at liip.ch
Thu Oct 3 07:33:45 UTC 2013


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****
>
> *[image: cid:image002.jpg at 01CE61F8.52552AE0]* <http://www.mn.gov/oet>**
>
> Information Technology for Minnesota Government   *|*   mn.gov/oet<http://www.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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20131003/cbd894f7/attachment-0001.html>


More information about the ckan-dev mailing list