Skip to content

Commit

Permalink
[#1251] allways pass preview as params
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Nov 13, 2013
1 parent fa49b54 commit 7a4c443
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
18 changes: 10 additions & 8 deletions ckan/controllers/package.py
Expand Up @@ -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})
Expand All @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions ckan/templates/package/snippets/resource_view.html
Expand Up @@ -21,11 +21,10 @@ <h1 class="resource-view-title">{{resource_view['title']}}</h1>
</a>
</p>
</div>
{% 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 %}
<iframe src="{{ src }}" frameborder="0" width="100%" data-module="data-viewer">
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/view_edit_base.html
Expand Up @@ -19,7 +19,7 @@
{% block primary_content_inner %}
{% block form %}{% endblock %}
{% if to_preview %}
{% include 'package/snippets/resource_view.html' %}
{% snippet 'package/snippets/resource_view.html', resource_view=resource_view, resource=resource, package=package, to_preview=True %}
{% endif %}
{% endblock %}

Expand Down

0 comments on commit 7a4c443

Please sign in to comment.