Frage

I want to create an extension to preview GTFS data - though my question is more about just how to create an extension to preview data.

Looking through the documentation and code I've found.

And these examples of existing preview extension:

Is there an example of an absolutely minimal extension to do previewing or tips on how I would go about this for GTFS (what's the best example to base my work off)?

War es hilfreich?

Lösung

I suggest that you have a look at the Text preview extension. It is reasonably small and covers all important parts such as how to let CKAN know that the extension can preview a file, how to load templates, how to load javascript and css and how to use the resource proxy (which is there to get around the same origin policy).

The current version of the plugin in CKAN uses a feature that allows defining how reasonable an extension can preview files which is not available in older CKANs.

There is a json preview extension in the stable version 2.0 of CKAN which is slightly smaller that the text-preview and supports older CKANs as well.

A minimal preview plugin looks something like (without the template):

import ckan.plugins as p

class Preview(p.SingletonPlugin):
    p.implements(p.IResourcePreview, inherit=True)

    def can_preview(self, data_dict):
        format = data_dict['resource']['format']
        return format.lower() == 'gtfs'

    def preview_template(self, context, data_dict):
        return 'preview.html'
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top