Skip to content

Commit

Permalink
Clean up the pre render method interface
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Oct 19, 2012
1 parent 437ed46 commit cb962d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
9 changes: 6 additions & 3 deletions ckan/controllers/package.py
Expand Up @@ -1324,8 +1324,11 @@ def resource_datapreview(self, id, resource_id):
This could be an img tag where the image is loaded directly or an iframe that
embeds a webpage, recline or a pdf preview.
'''
context = {'model': model, 'session': model.Session,
'user': c.user or c.author}
context = {
'model': model,
'session': model.Session,
'user': c.user or c.author
}

try:
c.resource = get_action('resource_show')(context,
Expand All @@ -1341,7 +1344,7 @@ def resource_datapreview(self, id, resource_id):
log.warn('Multiple previews are possible. {0}'.format(plugins_that_can_preview))

plugin = plugins_that_can_preview[0]
plugin.setup_template_variables(context, c)
plugin.setup_template_variables(context, {'resource': c.resource, 'package': c.package})

except NotFound:
abort(404, _('Resource not found'))
Expand Down
13 changes: 0 additions & 13 deletions ckan/lib/helpers.py
Expand Up @@ -1290,19 +1290,6 @@ def resource_preview(resource, pkg_id):
directly = False
url = ''

'''
if resource.get('datastore_active') or format_lower in ['csv', 'xls', 'tsv']:
url = url_for(controller='package', action='resource_datapreview',
resource_id=resource['id'], preview_type='recline', id=pkg_id, qualified=True)
elif format_lower in PDF:
url = url_for(controller='package', action='resource_datapreview',
resource_id=resource['id'], preview_type='pdf', id=pkg_id, qualified=True)
elif format_lower == 'jsonp':
url = url_for(controller='package', action='resource_datapreview',
resource_id=resource['id'], preview_type='json', id=pkg_id, qualified=True)
elif format_lower in LOADABLE:
url = resource['url']'''

if _can_be_previewed(resource):
url = url = url_for(controller='package', action='resource_datapreview',
resource_id=resource['id'], id=pkg_id, qualified=True)
Expand Down
3 changes: 1 addition & 2 deletions ckan/plugins/interfaces.py
Expand Up @@ -209,10 +209,9 @@ def requires_same_orign(self, resource):
a different domain because of the same origin policy.
'''

def setup_template_variables(self, context, c):
def setup_template_variables(self, context, data_dict):
'''
Add variables to c just prior to the template being rendered.
``resource``, ``package`` and ``resource_json`` are already defined.
'''

def preview_template(self, context):
Expand Down

0 comments on commit cb962d4

Please sign in to comment.