Skip to content

Commit

Permalink
use generic action for previews
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Sep 24, 2012
1 parent b232d23 commit ca908d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 48 deletions.
6 changes: 1 addition & 5 deletions ckan/config/routing.py
Expand Up @@ -213,12 +213,8 @@ def make_map():
action='resource_embedded_dataviewer')
m.connect('/dataset/{id}/resource/{resource_id}/viewer',
action='resource_embedded_dataviewer', width="960", height="800")
m.connect('/dataset/{id}/resource/{resource_id}/datapreview',
m.connect('/dataset/{id}/resource/{resource_id}/datapreview/{style}',
action='resource_datapreview')
m.connect('/dataset/{id}/resource/{resource_id}/pdfpreview',
action='resource_pdfpreview')
m.connect('/dataset/{id}/resource/{resource_id}/jsonpreview',
action='resource_jsonpreview')

# group
map.redirect('/groups', '/group')
Expand Down
40 changes: 2 additions & 38 deletions ckan/controllers/package.py
Expand Up @@ -1279,7 +1279,7 @@ def _parse_recline_state(self, params):
recline_state.pop(k)
return recline_state

def resource_datapreview(self, id, resource_id):
def resource_datapreview(self, id, resource_id, style):
'''
Embeded page for a resource data-preview.
'''
Expand All @@ -1295,40 +1295,4 @@ def resource_datapreview(self, id, resource_id):
abort(404, _('Resource not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read resource %s') % id)
return render('dataviewer/recline.html')

def resource_pdfpreview(self, id, resource_id):
'''
Embeded page for a resource pdf-preview.
'''
context = {'model': model, 'session': model.Session,
'user': c.user or c.author}

try:
c.resource = get_action('resource_show')(context,
{'id': resource_id})
c.package = get_action('package_show')(context, {'id': id})
c.resource_json = json.dumps(c.resource)
except NotFound:
abort(404, _('Resource not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read resource %s') % id)
return render('dataviewer/pdf.html')

def resource_jsonpreview(self, id, resource_id):
'''
Embeded page for a resource json-preview.
'''
context = {'model': model, 'session': model.Session,
'user': c.user or c.author}

try:
c.resource = get_action('resource_show')(context,
{'id': resource_id})
c.package = get_action('package_show')(context, {'id': id})
c.resource_json = json.dumps(c.resource)
except NotFound:
abort(404, _('Resource not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read resource %s') % id)
return render('dataviewer/json.html')
return render('dataviewer/{style}.html'.format(style=style))
10 changes: 5 additions & 5 deletions ckan/lib/helpers.py
Expand Up @@ -1324,13 +1324,13 @@ def resource_preview(resource, pkg_id):

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

0 comments on commit ca908d3

Please sign in to comment.