diff --git a/ckanext/pdfview/plugin.py b/ckanext/pdfview/plugin.py index 7717646..126f0b0 100644 --- a/ckanext/pdfview/plugin.py +++ b/ckanext/pdfview/plugin.py @@ -2,9 +2,12 @@ import ckan.plugins as p import ckan.lib.datapreview as datapreview +from ckan.common import is_flask_request log = logging.getLogger(__name__) +def request_type(): + return is_flask_request() class PdfView(p.SingletonPlugin): '''This extension views PDFs. ''' @@ -18,6 +21,7 @@ class PdfView(p.SingletonPlugin): p.implements(p.IConfigurer, inherit=True) p.implements(p.IConfigurable, inherit=True) p.implements(p.IResourceView, inherit=True) + p.implements(p.ITemplateHelpers) PDF = ['pdf', 'x-pdf', 'acrobat', 'vnd.pdf'] proxy_is_enabled = False @@ -52,3 +56,6 @@ def can_view(self, data_dict): def view_template(self, context, data_dict): return 'pdf.html' + + def get_helpers(self): + return {'pdfview_request_type': request_type} diff --git a/ckanext/pdfview/theme/templates/package/snippets/resource_view.html b/ckanext/pdfview/theme/templates/package/snippets/resource_view.html index 1e5413e..9c429a4 100644 --- a/ckanext/pdfview/theme/templates/package/snippets/resource_view.html +++ b/ckanext/pdfview/theme/templates/package/snippets/resource_view.html @@ -34,22 +34,44 @@
{% if not to_preview %} - {% set current_filters = request.str_GET.get('filters') %} - {% if current_filters %} - {% set src = h.url(qualified=true, controller='package', - action='resource_view', id=package['name'], - resource_id=resource['id'], - view_id=resource_view['id'], - filters=current_filters) %} + {% set is_flask = h.pdfview_request_type() %} + {# set current_filters correctly, depending on whether we are using flask or pylons #} + {% if is_flask %} + {% set current_filters = request.args.get('filters') %} + {% if current_filters %} + {% set src = h.url(qualified=true, controller='resource', + action='view', id=package['name'], + resource_id=resource['id'], + view_id=resource_view['id'], + filters=current_filters) %} + {% else %} + {% set src = h.url(qualified=true, controller='resource', + action='view', id=package['name'], + resource_id=resource['id'], + view_id=resource_view['id']) %} + {% endif %} {% else %} - {% set src = h.url(qualified=true, controller='package', - action='resource_view', id=package['name'], - resource_id=resource['id'], - view_id=resource_view['id']) %} + {% set current_filters = request.str_GET.get('filters') %} + {% if current_filters %} + {% set src = h.url(qualified=true, controller='package', + action='resource_view', id=package['name'], + resource_id=resource['id'], + view_id=resource_view['id'], + filters=current_filters) %} + {% else %} + {% set src = h.url(qualified=true, controller='package', + action='resource_view', id=package['name'], + resource_id=resource['id'], + view_id=resource_view['id']) %} + {% endif %} {% endif %} {% else %} {# When previewing we need to 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(qualified=true, controller='package', action='resource_view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(resource_view)}) %} + {% if is_flask %} + {% set src = h.url(qualified=true, controller='resource', action='view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(resource_view)}) %} + {% else %} + {% set src = h.url(qualified=true, controller='package', action='resource_view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(resource_view)}) %} + {% endif %} {% endif %}