Skip to content

Commit

Permalink
Merge branch '1251-resource-view' of github.com:okfn/ckan into 1251-r…
Browse files Browse the repository at this point in the history
…esource-view
  • Loading branch information
kindly committed Nov 8, 2013
2 parents 3f1f484 + afff845 commit 2cfed64
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 29 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
5 changes: 0 additions & 5 deletions ckanext/pdfpreview/plugin.py
Expand Up @@ -5,11 +5,6 @@

log = logging.getLogger(__name__)

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


class PdfPreview(p.SingletonPlugin):
'''This extension previews PDFs. '''
Expand Down
26 changes: 22 additions & 4 deletions ckanext/reclinepreview/plugin.py
Expand Up @@ -5,7 +5,7 @@
import ckan.plugins.toolkit as toolkit

log = getLogger(__name__)
ignore_missing = p.toolkit.get_validator('ignore_missing')
ignore_empty = p.toolkit.get_validator('ignore_empty')
natural_number_validator = p.toolkit.get_validator('natural_number_validator')


Expand All @@ -17,8 +17,8 @@ class ReclineView(p.SingletonPlugin):
p.implements(p.IResourceView, inherit=True)

# schema fields that apply to all Recline views
schema = {'offset': [ignore_missing, natural_number_validator],
'limit': [ignore_missing, natural_number_validator]}
schema = {'offset': [ignore_empty, natural_number_validator],
'limit': [ignore_empty, natural_number_validator]}

def update_config(self, config):
'''
Expand All @@ -36,7 +36,7 @@ def can_view(self, data_dict):

def setup_template_variables(self, context, data_dict):
return {'resource_json': json.dumps(data_dict['resource']),
'resource_view_json': json.dumps(data_dict['resource_view'])}
'resource_view_json': json.dumps(data_dict['data'])}

def view_template(self, context, data_dict):
return 'recline_view.html'
Expand All @@ -61,11 +61,29 @@ class ReclineGraph(ReclineView):
This extension views resources using a Recline graph.
'''

graph_types = [{'value': 'lines-and-points',
'text': 'Lines and points'},
{'value': 'lines', 'text': 'Lines'},
{'value': 'points', 'text': 'Points'},
{'value': 'bars', 'text': 'Bars'},
{'value': 'columns', 'text': 'Columns'}]

def info(self):
# TODO: add validators
self.schema.update({
'graph_type': [ignore_empty],
'group_column': [ignore_empty],
'series_a': [ignore_empty]
})
return {'name': 'recline_graph',
'title': 'Graph',
'schema': self.schema}

def setup_template_variables(self, context, data_dict):
vars = ReclineView.setup_template_variables(self, context, data_dict)
vars.update({'graph_types': self.graph_types})
return vars

def form_template(self, context, data_dict):
return 'recline_graph_form.html'

Expand Down
Expand Up @@ -2,3 +2,7 @@

{{ form.input('offset', id='field-offset', label=_('Row offset'), placeholder=_('eg: 0'), value=data.offset, error=errors.offset, classes=['control-medium']) }}
{{ form.input('limit', id='field-limit', label=_('Number of rows'), placeholder=_('eg: 100'), value=data.limit, error=errors.limit, classes=['control-medium']) }}

{{ form.select('graph_type', label=_('Graph type'), options=graph_types, selected=data.graph_type, error=errors.graph_type) }}
{{ form.select('group_column', label=_('Group column (Axis 1)'), options=columns, selected=data.group_column, error=errors.graph_column) }}
{{ form.select('series_a', label=_('Series A (Axis 2)'), options=columns, selected=data.series_a, error=errors.series_a) }}

0 comments on commit 2cfed64

Please sign in to comment.