Skip to content

Commit

Permalink
Merge branch 'resource_update-use-package_update'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Jun 27, 2013
2 parents b2a3d47 + 8edbdbd commit 74d185f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -7,6 +7,15 @@
Changelog
---------

v2.2
====

API changes and deprecations:

* The edit() and after_update() methods of IPackageController plugins are now
called when updating a resource using the web frontend or the
resource_update API action [#1052]

v2.0.1 2013-06-11
=================

Expand Down
35 changes: 15 additions & 20 deletions ckan/logic/action/update.py
Expand Up @@ -207,31 +207,26 @@ def resource_update(context, data_dict):
raise NotFound(_('Resource was not found.'))

_check_access('resource_update', context, data_dict)
del context["resource"]

if 'schema' in context:
schema = context['schema']
else:
package_plugin = lib_plugins.lookup_package_plugin(
resource.resource_group.package.type)
schema = package_plugin.update_package_schema()['resources']
package_id = resource.resource_group.package.id
pkg_dict = _get_action('package_show')(context, {'id': package_id})

data, errors = _validate(data_dict, schema, context)
if errors:
model.Session.rollback()
raise ValidationError(errors)

rev = model.repo.new_revision()
rev.author = user
if 'message' in context:
rev.message = context['message']
for n, p in enumerate(pkg_dict['resources']):
if p['id'] == id:
break
else:
rev.message = _(u'REST API: Update object %s') % data.get("name", "")
logging.error('Could not find resource ' + id)
raise NotFound(_('Resource was not found.'))
pkg_dict['resources'][n] = data_dict

resource = model_save.resource_dict_save(data, context)
if not context.get('defer_commit'):
model.repo.commit()
return model_dictize.resource_dictize(resource, context)
try:
pkg_dict = _get_action('package_update')(context, pkg_dict)
except ValidationError, e:
errors = e.error_dict['resources'][n]
raise ValidationError(errors)

return pkg_dict['resources'][n]


def package_update(context, data_dict):
Expand Down
3 changes: 2 additions & 1 deletion ckan/tests/logic/test_action.py
Expand Up @@ -684,10 +684,11 @@ def test_19_update_resource(self):

resource_updated.pop('url')
resource_updated.pop('revision_id')
resource_updated.pop('revision_timestamp')
resource_created.pop('url')
resource_created.pop('revision_id')
resource_created.pop('revision_timestamp')
assert resource_updated == resource_created
assert_equal(resource_updated, resource_created)

def test_20_task_status_update(self):
package_created = self._add_basic_package(u'test_task_status_update')
Expand Down

0 comments on commit 74d185f

Please sign in to comment.