Skip to content

Commit

Permalink
[#1251] add resource view back in data_dict sent to all templates
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Nov 12, 2013
1 parent 387c327 commit 35c2184
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ckan/controllers/package.py
Expand Up @@ -1504,13 +1504,14 @@ def edit_view(self, id, resource_id, view_id=None):
package_type=package_type)

data_dict = {'package': c.pkg_dict, 'resource': c.resource,
'data': data}
'resource_view': data}

view_template = view_plugin.view_template(context, data_dict)
form_template = view_plugin.form_template(context, data_dict)

vars = {'form_template': form_template,
'view_template': view_template,
'data': data,
'errors': errors,
'error_summary': error_summary,
'to_preview': to_preview}
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/helpers.py
Expand Up @@ -1633,7 +1633,7 @@ def rendered_resource_view(resource_view, resource, package, embed=False):
'''
view_plugin = datapreview.get_view_plugin(resource_view['view_type'])
context = {}
data_dict = {'data': resource_view,
data_dict = {'resource_view': resource_view,
'resource': resource,
'package': package}
vars = view_plugin.setup_template_variables(context, data_dict) or {}
Expand Down
14 changes: 7 additions & 7 deletions ckan/templates/package/snippets/resource_view.html
@@ -1,9 +1,9 @@
<h1 class="resource-view-title">{{data['title']}}</h1>
<div class="resource-view-description">{{data['description']}}</div>
<h1 class="resource-view-title">{{resource_view['title']}}</h1>
<div class="resource-view-description">{{resource_view['description']}}</div>

<div class="module-content ckanext-datapreview">
{% if not h.resource_view_is_iframed(data) %}
{{ h.rendered_resource_view(data, resource, package) }}
{% if not h.resource_view_is_iframed(resource_view) %}
{{ h.rendered_resource_view(resource_view, resource, package) }}
{% else %}
<div class="data-viewer-error js-hide">
<p class="text-error">
Expand All @@ -21,12 +21,12 @@ <h1 class="resource-view-title">{{data['title']}}</h1>
</a>
</p>
</div>
{% if data.get('id') %}
{% set src = h.url(controller='package', action='resource_view', id=package['name'], resource_id=resource['id'], view_id=data['id']) %}
{% if resource_view.get('id') %}
{% 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 #}
{% set src = h.url(controller='package', action='resource_view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(data)}) %}
{% 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">
<p>{{ _('Your browser does not support iframes.') }}</p>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/reclinepreview/plugin.py
Expand Up @@ -36,7 +36,7 @@ def can_view(self, data_dict):

def setup_template_variables(self, context, data_dict):
return {'resource_json': json.dumps(data_dict['resource']),
'resource_view_json': json.dumps(data_dict['data'])}
'resource_view_json': json.dumps(data_dict['resource_view'])}

def view_template(self, context, data_dict):
return 'recline_view.html'
Expand Down

0 comments on commit 35c2184

Please sign in to comment.