diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py
index c38f893d9da..20fb0b602ee 100644
--- a/ckan/controllers/package.py
+++ b/ckan/controllers/package.py
@@ -381,12 +381,9 @@ def read(self, id, format='html'):
# can the resources be previewed?
for resource in c.pkg_dict['resources']:
- try:
- get_action('resource_view_list')(
- context, {'id': resource['id']})
- resource['has_views'] = True
- except NotFound:
- resource['has_views'] = False
+ resource_views = get_action('resource_view_list')(
+ context, {'id': resource['id']})
+ resource['has_views'] = len(resource_views) > 0
self._setup_template_variables(context, {'id': id},
package_type=package_type)
@@ -1198,14 +1195,10 @@ def resource_read(self, id, resource_id):
c.related_count = c.pkg.related_count
- vars = {}
- try:
- vars['resource_views'] = get_action('resource_view_list')(
- context, {'id': resource_id})
- c.resource['has_views'] = True
- except NotFound:
- vars['resource_views'] = []
- c.resource['has_views'] = False
+ resource_views = get_action('resource_view_list')(
+ context, {'id': resource_id})
+ vars = {'resource_views': resource_views}
+ c.resource['has_views'] = len(resource_views) > 0
return render('package/resource_read.html', extra_vars=vars)
diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py
index ee93b0ce8c2..11401a2d788 100644
--- a/ckan/lib/helpers.py
+++ b/ckan/lib/helpers.py
@@ -1649,6 +1649,13 @@ def view_resource_url(resource_view, resource, package, **kw):
'''
return resource['url']
+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
@@ -1853,6 +1860,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',
diff --git a/ckan/templates/package/snippets/resource_view.html b/ckan/templates/package/snippets/resource_view.html
index 537b723ce46..dd287197851 100644
--- a/ckan/templates/package/snippets/resource_view.html
+++ b/ckan/templates/package/snippets/resource_view.html
@@ -1,6 +1,28 @@
-{% set rendered_resource_view = h.rendered_resource_view(resource_view, resource, package) %}
-
-
{{resource_view['title']}}
+{{resource_view['title']}}
{{resource_view['description']}}
-{{rendered_resource_view}}
+
+ {% if not h.resource_view_is_iframed(resource_view) %}
+ {{ h.rendered_resource_view(resource_view, resource, package) }}
+ {% else %}
+
+
+ {% endif %}
+
diff --git a/ckan/templates/package/view_edit_base.html b/ckan/templates/package/view_edit_base.html
index d3c98160b6f..d0b084f2236 100644
--- a/ckan/templates/package/view_edit_base.html
+++ b/ckan/templates/package/view_edit_base.html
@@ -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 %}
diff --git a/ckanext/imageview/plugin.py b/ckanext/imageview/plugin.py
index d62efb2578b..615e710a6e0 100644
--- a/ckanext/imageview/plugin.py
+++ b/ckanext/imageview/plugin.py
@@ -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
diff --git a/ckanext/imageview/tests/__init__.py b/ckanext/imageview/tests/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/ckanext/imageview/tests/test_view.py b/ckanext/imageview/tests/test_view.py
new file mode 100644
index 00000000000..73f31c72bc0
--- /dev/null
+++ b/ckanext/imageview/tests/test_view.py
@@ -0,0 +1,46 @@
+import pylons.config as config
+import paste.fixture
+
+import ckan.config.middleware as middleware
+import ckan.model as model
+import ckan.lib.helpers as h
+import ckan.lib.create_test_data as create_test_data
+import ckan.plugins as p
+import ckan.tests as tests
+
+
+class TestImageView(tests.WsgiAppCase):
+
+ @classmethod
+ def setup_class(cls):
+ cls.config_templates = config['ckan.legacy_templates']
+ config['ckan.legacy_templates'] = 'false'
+ wsgiapp = middleware.make_app(config['global_conf'], **config)
+ cls.app = paste.fixture.TestApp(wsgiapp)
+
+ create_test_data.CreateTestData.create()
+
+ context = {'model': model,
+ 'session': model.Session,
+ 'user': model.User.get('testsysadmin').name}
+
+ cls.package = model.Package.get('annakarenina')
+ cls.resource_id = cls.package.resources[1].id
+ cls.resource_view = {'resource_id': cls.resource_id,
+ 'view_type': u'image',
+ 'title': u'Image View',
+ 'description': u'A nice view',
+ 'image_url': 'test-image-view-url'}
+ p.toolkit.get_action('resource_view_create')(
+ context, cls.resource_view)
+
+ @classmethod
+ def teardown_class(cls):
+ config['ckan.legacy_templates'] = cls.config_templates
+ model.repo.rebuild_db()
+
+ def test_img_is_shown(self):
+ url = h.url_for(controller='package', action='resource_read',
+ id=self.package.name, resource_id=self.resource_id)
+ result = self.app.get(url)
+ assert self.resource_view['image_url'] in result