[ckan-dev] Merging package and resource creation

Ian Ward ian at excess.org
Thu Jan 7 20:42:58 UTC 2016


I found a little trick that works for skipping the resource creation
step in the dataset create form:

https://github.com/ckan/ckanext-scheming/blob/master/ckanext/scheming/templates/scheming/package/snippets/package_form.html#L28-L29

That should let you remove your redirect.

On Thu, Jan 7, 2016 at 2:34 PM, Mariano Falcon <mf2286 at gmail.com> wrote:
> My employer wants to simplify their ckan app datasets submission steps,
> creating the dataset and the resource directly in the same form(enforcing
> exclusively only one resource per dataset).  Right now, in order to create a
> dataset, you have to go through two "stages": dataset/package creation and
> then resource/s creation.
>
> I don't see a simple way to do this. My first try is the following:
>
> 1) Create an extension in which, after dataset creation, calls a
> 'resource_create' action.
>
> class DatasetFormPlugin(plugins.SingletonPlugin,
> toolkit.DefaultDatasetForm):
>     plugins.implements(plugins.IDatasetForm)
>     plugins.implements(plugins.IConfigurer)
>     plugins.implements(plugins.IPackageController, inherit=True)
>
>
>     def after_create(self, context, data_dict):
>         res_context = {'model': ckan.model, 'session': ckan.model.Session,
>            'user': pylons.c.user or pylons.c.author}
>
>         res_data_dict = {'clear_upload': u'', 'description':'some data',
> 'format': u'', 'name': u'data_dict['name']', 'package_id':
> data_dict['name'], 'url': u'http://test.com/data.json'}
>         toolkit.get_action('resource_create')(res_context, res_data_dict)
>
> 2) Extend /templates/paclage/snippets/package_form.html to remove stages:
>
> {% ckan_extends %}
>
>
> <form id="dataset-edit" class="dataset-form form-horizontal" method="post"
> action="{{ action }}" data-module="basic-form">
>   {% block stages %}
>   {% endblock %}
> </form>
>
> 3) Add custom fields to the template(resource url/file path)
>
> 4) Modify ckan core to redirect to /datasets after clicking the 'Add data'
> button on dataset form(stage 1).
>
> I know this is clearly not the correct way to accomplish this task,
> specially the step 4. I tried finding a better way but I don't seem to get
> it. Maybe you can give me some pointers.
>
> Thanks,
> Mariano.
> --
> Mariano Falcón
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>



More information about the ckan-dev mailing list