Skip to content

Commit

Permalink
[#1251] fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Nov 4, 2013
2 parents eb5bf29 + 5737dcd commit e1e41b2
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 31 deletions.
25 changes: 15 additions & 10 deletions ckan/controllers/package.py
Expand Up @@ -381,8 +381,12 @@ def read(self, id, format='html'):

# can the resources be previewed?
for resource in c.pkg_dict['resources']:
resource['can_be_previewed'] = self._resource_preview(
{'resource': resource, 'package': c.pkg_dict})
try:
get_action('resource_view_list')(
context, {'id': resource['id']})
resource['has_views'] = True
except NotFound:
resource['has_views'] = False

self._setup_template_variables(context, {'id': id},
package_type=package_type)
Expand Down Expand Up @@ -1194,15 +1198,16 @@ def resource_read(self, id, resource_id):

c.related_count = c.pkg.related_count

c.resource['can_be_previewed'] = self._resource_preview(
{'resource': c.resource, 'package': c.package})
return render('package/resource_read.html')
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

def _resource_preview(self, data_dict):
return bool(datapreview.res_format(data_dict['resource'])
in datapreview.direct() + datapreview.loadable()
or datapreview.get_preview_plugin(
data_dict, return_first=True))
return render('package/resource_read.html', extra_vars=vars)

def resource_download(self, id, resource_id):
"""
Expand Down
6 changes: 4 additions & 2 deletions ckan/lib/datapreview.py
Expand Up @@ -122,8 +122,11 @@ def get_preview_plugin(data_dict, return_first=False):
key=lambda x: x['quality'])['plugin']
return preview_plugin

def get_view_plugin(view_type):

def get_view_plugin(view_type):
'''
Returns the IResourceView plugin associated with the given view_type.
'''
for plugin in p.PluginImplementations(p.IResourceView):
info = plugin.info()
name = info.get('name')
Expand All @@ -138,4 +141,3 @@ def get_allowed_view_plugins(data_dict):
if plugin.can_preview(data_dict):
can_preview.append(plugin)
return can_preview

15 changes: 15 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -1625,6 +1625,20 @@ def get_allowed_view_types(resource, package):
allowed_view_types.sort(key=lambda item: item[1])
return allowed_view_types

def rendered_resource_view(resource_view, resource, package):
'''
Returns a rendered resource view snippet.
'''
view_plugin = datapreview.get_view_plugin(resource_view['view_type'])
context = {}
data_dict = {'resource_view': resource_view,
'resource': resource,
'package': package}
vars = view_plugin.setup_template_variables(context, data_dict) or {}
template = view_plugin.preview_template(context, data_dict)
return snippet(template, **vars)


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 @@ -1827,6 +1841,7 @@ def get_site_statistics():
'render_markdown',
'format_resource_items',
'resource_preview',
'rendered_resource_view',
'SI_number_span',
'localised_number',
'localised_SI_number',
Expand Down
2 changes: 2 additions & 0 deletions ckan/logic/action/get.py
Expand Up @@ -903,6 +903,7 @@ def resource_view_show(context, data_dict):
_check_access('resource_view_show', context, data_dict)
return model_dictize.resource_view_dictize(resource_view, context)


def resource_view_list(context, data_dict):
'''
Return the metadata of a resource_view.
Expand All @@ -923,6 +924,7 @@ def resource_view_list(context, data_dict):
resource_views = q.order_by(model.ResourceView.order).all()
return model_dictize.resource_view_list_dictize(resource_views, context)


def resource_status_show(context, data_dict):
'''Return the statuses of a resource's tasks.
Expand Down
11 changes: 6 additions & 5 deletions ckan/logic/schema.py
Expand Up @@ -588,9 +588,10 @@ def default_create_resource_view_schema():


def default_update_resource_view_schema():
schema = default_create_resource_view_schema()
schema.update({'id': [not_missing, not_empty, unicode]})
schema.update({'resource_id': [ignore_missing, resource_id_exists ]})
schema.update({'view_type': [ignore]}) #can not change after create
schema = default_resource_view_schema()
schema.update({
'id': [not_missing, not_empty, unicode],
'resource_id': [ignore_missing, resource_id_exists],
'view_type': [ignore] # can not change after create
})
return schema

1 change: 1 addition & 0 deletions ckan/plugins/interfaces.py
Expand Up @@ -238,6 +238,7 @@ def preview_template(self, context, data_dict):
The ``data_dict`` contains the resource and the package.
'''


class IResourcePreview(Interface):
''' For backwards compatibility with the old resource preview code. '''

Expand Down
10 changes: 7 additions & 3 deletions ckan/templates/package/resource_read.html
Expand Up @@ -36,7 +36,7 @@
<i class="icon-eye-open"></i> {{ _('View') }}
{% elif res.resource_type == 'api' %}
<i class="icon-key"></i> {{ _('API Endpoint') }}
{% elif not res.can_be_previewed %}
{% elif not res.has_views %}
<i class="icon-external-link"></i> {{ _('Go to resource') }}
{% else %}
<i class="icon-download"></i> {{ _('Download') }}
Expand Down Expand Up @@ -72,8 +72,12 @@ <h3>{{ _('From the dataset abstract') }}</h3>
{% endblock %}
</div>
</div>
{% block data_preview %}
{{ h.resource_preview(c.resource, c.package) }}
{% block resource_views %}
<div class="resource-views">
{% for resource_view in resource_views %}
{% snippet 'package/snippets/resource_view.html', resource_view=resource_view, resource=c.resource, package=c.package %}
{% endfor %}
</div>
{% endblock %}
</section>
{% endblock %}
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/package/snippets/resource_item.html
Expand Up @@ -28,7 +28,7 @@
{% block resource_item_explore_links %}
<li>
<a href="{{ url }}">
{% if res.can_be_previewed %}
{% if res.has_views %}
<i class="icon-bar-chart"></i>
{{ _('Preview') }}
{% else %}
Expand All @@ -39,7 +39,7 @@
</li>
<li>
<a href="{{ res.url }}" class="resource-url-analytics" target="_blank">
{% if res.can_be_previewed %}
{% if res.has_views %}
<i class="icon-download"></i>
{{ _('Download') }}
{% else %}
Expand Down
6 changes: 6 additions & 0 deletions ckan/templates/package/snippets/resource_view.html
@@ -0,0 +1,6 @@
{% set rendered_resource_view = h.rendered_resource_view(resource_view, resource, package) %}

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

{{rendered_resource_view}}
11 changes: 2 additions & 9 deletions ckanext/imageview/plugin.py
Expand Up @@ -3,15 +3,8 @@
import ckan.plugins as p
from ckan.lib.navl.validators import ignore_empty

from ckan.common import json

log = logging.getLogger(__name__)

try:
import ckanext.resourceproxy.plugin as proxy
except ImportError:
pass

DEFAULT_IMAGE_FORMATS = ['png', 'jpeg', 'jpg', 'gif']


Expand All @@ -34,7 +27,7 @@ def can_preview(self, data_dict):
return True

def setup_template_variables(self, context, data_dict):
return
return {'image_url': data_dict['resource_view']['image_url']}

def preview_template(self, context, data_dict):
return 'image.html'
return 'image_view.html'
1 change: 1 addition & 0 deletions ckanext/imageview/theme/templates/image_view.html
@@ -0,0 +1 @@
<img src="{{image_url}}"></img>

0 comments on commit e1e41b2

Please sign in to comment.