Skip to content

Commit

Permalink
[#1251] Add iframe to resource view snippet.
Browse files Browse the repository at this point in the history
Allow view plugins to disable iframing by setting
'iframed': False in their info dicts.

Actual iframe URL not included yet.
  • Loading branch information
johnglover committed Nov 5, 2013
1 parent cbe662f commit 65796b9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
9 changes: 9 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -1642,6 +1642,14 @@ def rendered_resource_view(resource_view, resource, package):
return snippet(template, **data_dict)


def resource_view_is_iframed(resource_view):
'''
Returns true if the given resource view should be displayed in an iframe.
'''
view_plugin = datapreview.get_view_plugin(resource_view['view_type'])
return view_plugin.info().get('iframed', True)


def list_dict_filter(list_, search_field, output_field, value):
''' Takes a list of dicts and returns the value of a given key if the
item has a matching value for a supplied key
Expand Down Expand Up @@ -1845,6 +1853,7 @@ def get_site_statistics():
'format_resource_items',
'resource_preview',
'rendered_resource_view',
'resource_view_is_iframed',
'SI_number_span',
'localised_number',
'localised_SI_number',
Expand Down
30 changes: 26 additions & 4 deletions ckan/templates/package/snippets/resource_view.html
@@ -1,6 +1,28 @@
{% set rendered_resource_view = h.rendered_resource_view(resource_view, resource, package) %}

<h1>{{resource_view['title']}}</h1>
<h1 class="resource-view-title">{{resource_view['title']}}</h1>
<div class="resource-view-description">{{resource_view['description']}}</div>

{{rendered_resource_view}}
<div class="module-content ckanext-datapreview">
{% 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">
<i class="icon-info-sign"></i>
{{ _('This resource view is not available at the moment.') }}
<a href="#" data-toggle="collapse" data-target="#data-view-error">
{{ _('Click here for more information.') }}
</a>
</p>
<p id="data-view-error" class="collapse"></p>
<p>
<a href="{{ raw_resource_url }}" class="btn btn-large resource-url-analytics" target="_blank">
<i class="icon-large icon-download"></i>
{{ _('Download resource') }}
</a>
</p>
</div>
<iframe src="" frameborder="0" width="100%" data-module="data-viewer">
<p>{{ _('Your browser does not support iframes.') }}</p>
</iframe>
{% endif %}
</div>
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 %}
{{ h.rendered_resource_view(data, c.resource, c.pkg_dict) }}
{% snippet 'package/snippets/resource_view.html', resource_view=data, resource=c.resource, package=c.pkg_dict %}
{% endif %}
{% endblock %}

Expand Down
3 changes: 2 additions & 1 deletion ckanext/imageview/plugin.py
Expand Up @@ -19,7 +19,8 @@ def update_config(self, config):
def info(self):
return {'name': 'image',
'title': 'Image',
'schema': {'image_url': [ignore_empty, unicode]}}
'schema': {'image_url': [ignore_empty, unicode]},
'iframed': False}

def can_view(self, data_dict):
return True
Expand Down

0 comments on commit 65796b9

Please sign in to comment.