From 7a4c443f06c889c0a7febd0b8869e866569ada42 Mon Sep 17 00:00:00 2001
From: kindly
Date: Wed, 13 Nov 2013 09:58:53 +0000
Subject: [PATCH] [#1251] allways pass preview as params
---
ckan/controllers/package.py | 18 ++++++++++--------
.../package/snippets/resource_view.html | 5 ++---
ckan/templates/package/view_edit_base.html | 2 +-
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py
index 0c82318194e..4d72979f7a3 100644
--- a/ckan/controllers/package.py
+++ b/ckan/controllers/package.py
@@ -1552,7 +1552,13 @@ def resource_view(self, id, resource_id, view_id=None):
except NotAuthorized:
abort(401, _('Unauthorized to read resource %s') % resource_id)
- if view_id:
+ view = None
+ if request.params.get('resource_view', ''):
+ try:
+ view = json.loads(request.params.get('resource_view', ''))
+ except ValueError:
+ abort(409, _('Bad resource view data'))
+ elif view_id:
try:
view = get_action('resource_view_show')(
context, {'id': view_id})
@@ -1561,13 +1567,9 @@ def resource_view(self, id, resource_id, view_id=None):
except NotAuthorized:
abort(401,
_('Unauthorized to read resource view %s') % view_id)
- else:
- try:
- view = json.loads(request.params.get('resource_view', ''))
- except ValueError:
- abort(409, _('Bad resource view data'))
- if not view or not isinstance(view, dict):
- abort(404, _('Resource view not supplied'))
+
+ if not view or not isinstance(view, dict):
+ abort(404, _('Resource view not supplied'))
return h.rendered_resource_view(view, resource, package, embed=True)
diff --git a/ckan/templates/package/snippets/resource_view.html b/ckan/templates/package/snippets/resource_view.html
index ef373cac00a..265c4b3a327 100644
--- a/ckan/templates/package/snippets/resource_view.html
+++ b/ckan/templates/package/snippets/resource_view.html
@@ -21,11 +21,10 @@ {{resource_view['title']}}
- {% if resource_view.get('id') %}
+ {% if not to_preview %}
{% set src = h.url(controller='package', action='resource_view', id=package['name'], resource_id=resource['id'], view_id=resource_view['id']) %}
{% else %}
- {# When creating a new view no view_id exists, but we still want to preview it, so we stick the whole resource_view as a param as there is no other way to pass to information on to
- the iframe #}
+ {# When previewing we neet to stick the whole resource_view as a param as there is no other way to pass to information on to the iframe #}
{% set src = h.url(controller='package', action='resource_view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(resource_view)}) %}
{% endif %}