Skip to content

Commit

Permalink
[#1251] a few changed to how interfaces work
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Nov 4, 2013
1 parent 5cfaff2 commit f0f771e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ckan/controllers/package.py
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -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):
Expand Down
19 changes: 16 additions & 3 deletions ckan/plugins/interfaces.py
Expand Up @@ -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``.
'''
Expand All @@ -231,17 +231,30 @@ 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.
The ``data_dict`` contains the resource and the package.
'''


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):
'''
Expand Down

0 comments on commit f0f771e

Please sign in to comment.