[ckan-dev] Modify resource URL

Sean Hammond sean.hammond at okfn.org
Fri May 10 11:35:46 UTC 2013


> I'm trying to change some things in my 1.8 installed version of CKAN,
> specifically when i am introducing a new dataset, I would like to manipulate
> the url that the user enters before saving in the CKAN database.
> 
> I've been researching and I think it will be in CKAN / models / package.py
> but i'm not sure if the "def" of add_resource is where I should change the
> URL to manipulate before I save in the BBDD
> 
> Can you help me?. Thank you very much.

Hi, I haven't tried this to make sure, but I think you should be able to
do this using an IDatasetForm plugin, rather than by modifying the CKAN
source code. See this page for documentation about writing plugins:

http://docs.ckan.org/en/ckan-1.8/writing-extensions.html

In your IDatasetForm plugin's form_to_db_schema() method, you can return
a schema that includes a converter function on the url field. Something
like this:

    def form_to_db_schema(self):
        schema = super(ExampleIDatasetFormPlugin, self).form_to_db_schema()
        schema['url'].append(my_url_converter)
        return schema

Where `my_url_converter` is a function that takes two params - value and
context. `value` will be the value of the dataset's url, and the
function can modify and return it:

    def my_url_converter(value, context):
        value = ...
        return value

If you need any more help getting this working, would you mind posting
your question to the ckan tag on stackoverflow.com? That way the
question can be answered publicly, and the answer might be useful to
others how find it.

Thanks!




More information about the ckan-dev mailing list