[ckan-dev] customizing ckan.lib.dictization.model_save.package_dict_save()

David Raznick kindly at gmail.com
Wed Jun 27 20:17:18 UTC 2012


> Make my plugin implement IActions.package_update which is exactly the same
> as the ckan.logic.action.update.package_update except it calls my custom
> implementation of package_dict_save().

I would go with that one almost however I would wrap the logic
function rather than rewrite it.  I would also not rewrite
package_dict_save just run your function on the whole data_dict.

i.e in your IActions and override the package_update function.
That function should look something like this.

def package_update(context, data_dict)
       context['defer_commit'] = True ## defer the commit so this
function does the commiting as we want to commit everything at the
same time.
       ckan.logic.action.update.package_update(context,  data_dict)
## the original pakcage_update
       your_fuction(context, data_dict)  ## do the saving you need to do
       context['model'].repo.commit() ##commit everything together.


I recommend this way as it means that any change we make to
package_update and package_dict_save in future versions you will not
need replicate or be aware of. The only problem that could occur is if
we make an entity the same name as the one you are adding (which is
very unlikely).

Thanks

David




More information about the ckan-dev mailing list