Skip to content

Commit

Permalink
fix merge issue in branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Nov 5, 2013
2 parents 0ddeec8 + 65796b9 commit 82101eb
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 20 deletions.
21 changes: 7 additions & 14 deletions ckan/controllers/package.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -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
Expand Down Expand Up @@ -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',
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
Empty file.
46 changes: 46 additions & 0 deletions 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

0 comments on commit 82101eb

Please sign in to comment.