From f0f771e51666e014d2051373b1776158d1e6a34b Mon Sep 17 00:00:00 2001 From: kindly Date: Mon, 4 Nov 2013 10:13:11 +0000 Subject: [PATCH] [#1251] a few changed to how interfaces work --- ckan/controllers/package.py | 2 +- ckan/lib/helpers.py | 3 ++- ckan/plugins/interfaces.py | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py index ca47a2bc5b7..da1e1564e31 100644 --- a/ckan/controllers/package.py +++ b/ckan/controllers/package.py @@ -1511,7 +1511,7 @@ def edit_view(self, id, resource_id, view_id=None): package_type=package_type) data_dict = {'package': c.pkg_dict, 'resource': c.resource, - 'view': data} + 'resource_view': data} view_plugin.setup_template_variables(context, data_dict) preview_template = view_plugin.preview_template(context, data_dict) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 82617d3d047..26fc7934d39 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -1636,7 +1636,8 @@ def rendered_resource_view(resource_view, resource, package): 'package': package} vars = view_plugin.setup_template_variables(context, data_dict) or {} template = view_plugin.preview_template(context, data_dict) - return snippet(template, **vars) + data_dict.update(vars) + return snippet(template, **data_dict) def list_dict_filter(list_, search_field, output_field, value): diff --git a/ckan/plugins/interfaces.py b/ckan/plugins/interfaces.py index 89fccd32b05..9dc55104ac3 100644 --- a/ckan/plugins/interfaces.py +++ b/ckan/plugins/interfaces.py @@ -218,7 +218,7 @@ def info(self): ''' return {'name': self.__class__.__name__} - def can_preview(self, data_dict): + def can_view(self, data_dict): '''Return info on whether the plugin can preview the resource. return ``True`` or ``False``. ''' @@ -231,7 +231,14 @@ def setup_template_variables(self, context, data_dict): Change the url to a proxied domain if necessary. ''' - def preview_template(self, context, data_dict): + 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. + ''' + + def form_template(self, context, data_dict): ''' Returns a string representing the location of the template to be rendered for the read page. @@ -239,9 +246,15 @@ def preview_template(self, context, data_dict): ''' -class IResourcePreview(Interface): +class IResourcePreview(IResourceView): ''' For backwards compatibility with the old resource preview code. ''' + 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) + class ITagController(Interface): '''