Skip to content

Commit

Permalink
[ckan#3457]Create new resource view if resource format changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan authored and amercader committed Jun 21, 2017
1 parent aec3145 commit c08b0c5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ckan/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def resource_update(context, data_dict):
model = context['model']
user = context['user']
id = _get_or_bust(data_dict, "id")
old_resource = _get_action('resource_show')(context, {'id': id})

resource = model.Resource.get(id)
context["resource"] = resource
Expand Down Expand Up @@ -166,6 +167,19 @@ def resource_update(context, data_dict):

resource = _get_action('resource_show')(context, {'id': id})

if old_resource['format'] != resource['format']:
q = model.Session.query(model.ResourceView) \
.filter(model.ResourceView.resource_id == resource['id'])
resources_view_id = q.all()
if resources_view_id:
for view_id in resources_view_id:
_get_action(
'resource_view_delete')(context, {'id': view_id.id})
_get_action('package_create_default_resource_views')(
{'model': context['model'], 'user': context['user'],
'ignore_auth': True},
{'package': updated_pkg_dict})

for plugin in plugins.PluginImplementations(plugins.IResourceController):
plugin.after_update(context, resource)

Expand Down

0 comments on commit c08b0c5

Please sign in to comment.