Skip to content

Commit

Permalink
[#1251] Pass View template variables through to
Browse files Browse the repository at this point in the history
edit templates. Templates added using 'include'
instead of 'snippet'.

Edit and view templates did not have a consistent
name for the resource_view dict, have changed the
view templates to just 'data' for now.
  • Loading branch information
johnglover committed Nov 7, 2013
1 parent 1cca7da commit ffbd9e5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
14 changes: 8 additions & 6 deletions ckan/controllers/package.py
Expand Up @@ -1385,7 +1385,7 @@ def resource_views(self, id, resource_id):

try:
check_access('package_update', context, data_dict)
except NotAuthorized, e:
except NotAuthorized:
abort(401, _('User %r not authorized to edit %s') % (c.user, id))
# check if package exists
try:
Expand Down Expand Up @@ -1504,18 +1504,19 @@ def edit_view(self, id, resource_id, view_id=None):
package_type=package_type)

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

view_plugin.setup_template_variables(context, data_dict)
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}
vars.update(
view_plugin.setup_template_variables(context, data_dict) or {})
vars.update(data_dict)

if view_id:
return render('package/edit_view.html', extra_vars=vars)
Expand Down Expand Up @@ -1557,11 +1558,12 @@ def resource_view(self, id, resource_id, view_id=None):
except NotFound:
abort(404, _('Resource view not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read resource view %s') % view_id)
abort(401,
_('Unauthorized to read resource view %s') % view_id)
else:
try:
view = json.loads(request.params.get('resource_view', ''))
except ValueError, e:
except ValueError:
abort(409, _('Bad resource view data'))
if not view or not isinstance(view, dict):
abort(404, _('Resource view not supplied'))
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 = {'resource_view': resource_view,
data_dict = {'data': resource_view,
'resource': resource,
'package': package}
vars = view_plugin.setup_template_variables(context, data_dict) or {}
Expand Down
3 changes: 1 addition & 2 deletions ckan/templates/package/edit_view.html
Expand Up @@ -9,7 +9,7 @@

{% block form %}
<form class="dataset-form dataset-resource-form form-horizontal" method="post" data-module="basic-form resource-form">
{% snippet 'package/snippets/view_form.html', data=data, errors=errors, error_summary=error_summary, form_template=form_template %}
{% include 'package/snippets/view_form.html' %}
<div class="form-actions">
<button class="btn btn-danger pull-left" name="delete" value="Delete"> {{ _('Delete') }} </button>
<button class="btn btn-primary" name="preview" value="True" type="submit">{{ _('Preview Update') }}</button>
Expand All @@ -21,4 +21,3 @@
{% block content_primary_nav %}
<li class="active"><a href="#"><i class="icon-edit"></i> {{ _('Edit View') }}</a></li>
{% endblock %}

14 changes: 7 additions & 7 deletions ckan/templates/package/snippets/resource_view.html
@@ -1,9 +1,9 @@
<h1 class="resource-view-title">{{resource_view['title']}}</h1>
<div class="resource-view-description">{{resource_view['description']}}</div>
<h1 class="resource-view-title">{{data['title']}}</h1>
<div class="resource-view-description">{{data['description']}}</div>

<div class="module-content ckanext-datapreview">
{% if not h.resource_view_is_iframed(resource_view) %}
{{ h.rendered_resource_view(resource_view, resource, package) }}
{% if not h.resource_view_is_iframed(data) %}
{{ h.rendered_resource_view(data, 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">{{resource_view['title']}}</h1>
</a>
</p>
</div>
{% 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']) %}
{% if data.get('id') %}
{% set src = h.url(controller='package', action='resource_view', id=package['name'], resource_id=resource['id'], view_id=data['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(resource_view)}) %}
{% set src = h.url(controller='package', action='resource_view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(data)}) %}
{% endif %}
<iframe src="{{ src }}" frameborder="0" width="100%" data-module="data-viewer">
<p>{{ _('Your browser does not support iframes.') }}</p>
Expand Down
4 changes: 1 addition & 3 deletions ckan/templates/package/snippets/view_form.html
Expand Up @@ -10,7 +10,5 @@

{# form template is defined in ResouceView extention point #}
{% if form_template %}
{% snippet form_template, data=data, errors=errors %}
{% include form_template %}
{% endif %}


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 %}
{% snippet 'package/snippets/resource_view.html', resource_view=data, resource=c.resource, package=c.pkg_dict %}
{% include 'package/snippets/resource_view.html' %}
{% endif %}
{% endblock %}

Expand Down

0 comments on commit ffbd9e5

Please sign in to comment.