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 %}
{{ h.render_markdown(resource_view['description']) }}