diff --git a/README.rst b/README.rst index 543ba24..60b7ee3 100644 --- a/README.rst +++ b/README.rst @@ -5,18 +5,10 @@ .. image:: https://travis-ci.org/ckan/ckanext-pdfview.svg?branch=master :target: https://travis-ci.org/ckan/ckanext-pdfview -.. image:: https://img.shields.io/pypi/dm/ckanext-pdfview.svg - :target: https://pypi.python.org/pypi//ckanext-pdfview/ - :alt: Downloads - .. image:: https://img.shields.io/pypi/v/ckanext-pdfview.svg :target: https://pypi.python.org/pypi/ckanext-pdfview/ :alt: Latest Version -.. image:: https://img.shields.io/pypi/pyversions/ckanext-pdfview.svg - :target: https://pypi.python.org/pypi/ckanext-pdfview/ - :alt: Supported Python versions - .. image:: https://img.shields.io/pypi/status/ckanext-pdfview.svg :target: https://pypi.python.org/pypi/ckanext-pdfview/ :alt: Development Status diff --git a/bin/travis-build.bash b/bin/travis-build.bash index 13b3a0e..64e03fe 100644 --- a/bin/travis-build.bash +++ b/bin/travis-build.bash @@ -18,6 +18,9 @@ else git checkout $CKAN_TAG echo "CKAN version: ${CKAN_TAG#ckan-}" fi +# Unpin CKAN's psycopg2 dependency get an important bugfix +# https://stackoverflow.com/questions/47044854/error-installing-psycopg2-2-6-2 +sed -i '/psycopg2/c\psycopg2' requirements.txt python setup.py develop pip install -r requirements.txt pip install -r dev-requirements.txt diff --git a/ckanext/pdfview/plugin.py b/ckanext/pdfview/plugin.py index 7717646..495437a 100644 --- a/ckanext/pdfview/plugin.py +++ b/ckanext/pdfview/plugin.py @@ -1,10 +1,31 @@ import logging import ckan.plugins as p +import ckan.lib.helpers as h import ckan.lib.datapreview as datapreview log = logging.getLogger(__name__) +def get_ckan_version(): + try: + return float(h.ckan_version()[0:3]) + except AttributeError: + #So old that we can't ask CKAN this way, but let's be optimistic + return 2.4 + +def get_ckan_with_fa(): + if get_ckan_version() >= 2.7: + return True + else: + return False + +def get_bootstrap_version(): + public_setting = config.get('ckan.base_public_folder', 'public') + if public_setting == 'public-bs2' or get_ckan_version() <= 2.7: + return 2 + #Otherwise we're on 2.8+, or other folder; in that case assume 3 (future proofing) + else: + return 3 class PdfView(p.SingletonPlugin): '''This extension views PDFs. ''' @@ -16,6 +37,7 @@ class PdfView(p.SingletonPlugin): 'CKAN repository.') p.implements(p.IConfigurer, inherit=True) + p.implements(p.ITemplateHelpers, inherit=True) p.implements(p.IConfigurable, inherit=True) p.implements(p.IResourceView, inherit=True) @@ -52,3 +74,9 @@ def can_view(self, data_dict): def view_template(self, context, data_dict): return 'pdf.html' + + def get_helpers(self): + return { + 'pdfview_get_ckan_with_fa': get_ckan_with_fa, + 'pdfview_get_bootstrap_version': get_bootstrap_version + } diff --git a/ckanext/pdfview/theme/public/css/pdf.css b/ckanext/pdfview/theme/public/css/pdf.css index a4d0800..2c80c1b 100644 --- a/ckanext/pdfview/theme/public/css/pdf.css +++ b/ckanext/pdfview/theme/public/css/pdf.css @@ -1,4 +1,4 @@ body { - height: 500px; + height: 650px; overflow: hidden; -} \ No newline at end of file +} diff --git a/ckanext/pdfview/theme/templates/package/snippets/resource_view.html b/ckanext/pdfview/theme/templates/package/snippets/resource_view.html index 1e5413e..b2c1784 100644 --- a/ckanext/pdfview/theme/templates/package/snippets/resource_view.html +++ b/ckanext/pdfview/theme/templates/package/snippets/resource_view.html @@ -1,14 +1,44 @@ {% import 'macros/form.html' as form %} +{% if h.pdfview_get_ckan_with_fa() %} + {% set fullscreen_icon = "fa fa-arrows-alt" %} + {% set code_icon = "fa fa-code" %} + {% set info_icon = "fa fa-info-circle" %} + {% set download_icon = "fa fa-lg fa-arrow-circle-o-down" %} +{% else %} + {% set fullscreen_icon = "icon-fullscreen" %} + {% set code_icon = "icon-code" %} + {% set info_icon = "icon-info-sign" %} + {% set download_icon = "icon-large icon-download" %} +{% endif %} + +{% if h.pdfview_get_bootstrap_version >= 3 %} + {% set span6 = "col-md-6" %} +{% else %} + {% set span6 = "span6" %} +{% endif %} + +{% block resource_view %}
- - - {{ _("Embed") }} - +
+ {% block resource_view_actions %} + + + {{ _("Fullscreen") }} + + + + {{ _("Embed") }} + + {% block resource_view_actions_extras %}{% endblock %} + {% endblock %} +

{{ h.render_markdown(resource_view['description']) }}

{% if not to_preview and h.resource_view_is_filterable(resource_view) %} @@ -18,8 +48,8 @@ {{ h.rendered_resource_view(resource_view, resource, package) }} {% else %}
-

- +

+ {{ _('This resource view is not available at the moment.') }} {{ _('Click here for more information.') }} @@ -27,8 +57,8 @@

- - + + {{ _('Download resource') }}

@@ -36,42 +66,47 @@ {% if not to_preview %} {% set current_filters = request.str_GET.get('filters') %} {% if current_filters %} - {% set src = h.url(qualified=true, controller='package', + {% set src = h.url_for(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', + {% set src = h.url_for(qualified=true, controller='package', action='resource_view', id=package['name'], resource_id=resource['id'], view_id=resource_view['id']) %} {% 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)}) %} + {% set src = h.url_for(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 %}
-