[ckan-dev] Merging package and resource creation
Mariano Falcon
mf2286 at gmail.com
Thu Jan 7 19:34:06 UTC 2016
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20160107/c3e266a3/attachment-0002.html>
More information about the ckan-dev
mailing list