diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py index da1e1564e31..b4898a1844e 100644 --- a/ckan/controllers/package.py +++ b/ckan/controllers/package.py @@ -1501,7 +1501,6 @@ def edit_view(self, id, resource_id, view_id=None): except NotAuthorized: abort(401, _('Unauthorized to view View %s') % view_id) - view_type = view_type or request.GET.get('view_type') view_plugin = datapreview.get_view_plugin(view_type) if not view_plugin: @@ -1514,17 +1513,19 @@ def edit_view(self, id, resource_id, view_id=None): 'resource_view': data} view_plugin.setup_template_variables(context, data_dict) - preview_template = view_plugin.preview_template(context, data_dict) + view_template = view_plugin.view_template(context, data_dict) + form_template = view_plugin.form_template(context, data_dict) - vars = {'form_template': view_plugin.info().get('form_template'), - 'preview_template': preview_template, - 'data': data, 'errors': errors, 'error_summary': error_summary, + vars = {'form_template': form_template, + 'view_template': view_template, + 'data': data, + 'errors': errors, + 'error_summary': error_summary, 'to_preview': to_preview} if view_id: - return render('package/edit_view.html', extra_vars = vars) - return render('package/new_view.html', extra_vars = vars) - + return render('package/edit_view.html', extra_vars=vars) + return render('package/new_view.html', extra_vars=vars) def resource_datapreview(self, id, resource_id): ''' diff --git a/ckan/lib/datapreview.py b/ckan/lib/datapreview.py index b290e9b2e93..07eff5a9500 100644 --- a/ckan/lib/datapreview.py +++ b/ckan/lib/datapreview.py @@ -133,11 +133,10 @@ def get_view_plugin(view_type): if name == view_type: return plugin -def get_allowed_view_plugins(data_dict): - - can_preview = [] +def get_allowed_view_plugins(data_dict): + can_view = [] for plugin in p.PluginImplementations(p.IResourceView): - if plugin.can_preview(data_dict): - can_preview.append(plugin) - return can_preview + if plugin.can_view(data_dict): + can_view.append(plugin) + return can_view diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 26fc7934d39..8731015ad7a 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -1613,6 +1613,7 @@ def resource_preview(resource, package): resource_url=url, raw_resource_url=resource.get('url')) + def get_allowed_view_types(resource, package): data_dict = {'resource': resource, 'package': package} plugins = datapreview.get_allowed_view_plugins(data_dict) @@ -1625,6 +1626,7 @@ def get_allowed_view_types(resource, package): allowed_view_types.sort(key=lambda item: item[1]) return allowed_view_types + def rendered_resource_view(resource_view, resource, package): ''' Returns a rendered resource view snippet. @@ -1635,7 +1637,7 @@ def rendered_resource_view(resource_view, resource, package): 'resource': resource, 'package': package} vars = view_plugin.setup_template_variables(context, data_dict) or {} - template = view_plugin.preview_template(context, data_dict) + template = view_plugin.view_template(context, data_dict) data_dict.update(vars) return snippet(template, **data_dict) diff --git a/ckan/plugins/interfaces.py b/ckan/plugins/interfaces.py index 9dc55104ac3..b3a5093b319 100644 --- a/ckan/plugins/interfaces.py +++ b/ckan/plugins/interfaces.py @@ -225,24 +225,30 @@ def can_view(self, data_dict): def setup_template_variables(self, context, data_dict): ''' - Add variables to c just prior to the template being rendered. - The ``data_dict`` contains the resource and the package. + Add variables to the ``data_dict`` that is passed to the + template being rendered. + Should return a new dict instead of updating the input ``data_dict``. - Change the url to a proxied domain if necessary. + The ``data_dict`` contains: ``resource_view``, ``resource`` and + ``package``. ''' def view_template(self, context, data_dict): ''' Returns a string representing the location of the template to be rendered for the read page. - The ``data_dict`` contains the resource and the package. + + The ``data_dict`` contains: ``resource_view``, ``resource`` and + ``package``. ''' def form_template(self, context, data_dict): ''' Returns a string representing the location of the template to be rendered for the read page. - The ``data_dict`` contains the resource and the package. + + The ``data_dict`` contains: ``resource_view``, ``resource`` and + ``package``. ''' @@ -253,7 +259,7 @@ def can_preview(self, data_dict): return self.can_view(data_dict) def preview_template(self, context, data_dict): - return self.preview_template(context, data_dict) + return self.view_template(context, data_dict) class ITagController(Interface): diff --git a/ckan/templates/package/view_edit_base.html b/ckan/templates/package/view_edit_base.html index f3500cd773f..d3c98160b6f 100644 --- a/ckan/templates/package/view_edit_base.html +++ b/ckan/templates/package/view_edit_base.html @@ -19,7 +19,7 @@ {% block primary_content_inner %} {% block form %}{% endblock %} {% if to_preview %} - {% snippet preview_template, view=data, resource=c.resource, package=c.pkg_dict %} + {{ h.rendered_resource_view(data, c.resource, c.pkg_dict) }} {% endif %} {% endblock %}