Skip to content

Commit

Permalink
Merge pull request #44 from pdelboca/2.10-support
Browse files Browse the repository at this point in the history
Add support for 2.10
  • Loading branch information
amercader authored Apr 8, 2022
2 parents e4df796 + 9dfd2c2 commit 3acd4a5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
needs: lint
strategy:
matrix:
ckan-version: [2.9, 2.9-py2, 2.8, 2.7]
ckan-version: ["2.10", 2.9, 2.9-py2, 2.8, 2.7]
fail-fast: false

name: CKAN ${{ matrix.ckan-version }}
Expand All @@ -26,7 +26,7 @@ jobs:
image: openknowledge/ckan-dev:${{ matrix.ckan-version }}
services:
solr:
image: ckan/ckan-solr-dev:${{ matrix.ckan-version }}
image: ckan/ckan-solr:${{ matrix.ckan-version }}
postgres:
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
env:
Expand Down
31 changes: 16 additions & 15 deletions ckanext/pdfview/plugin.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
# encoding: utf-8

import logging
from six import text_type
import ckan.plugins as p

log = logging.getLogger(__name__)
ignore_empty = p.toolkit.get_validator('ignore_empty')
ignore_empty = p.toolkit.get_validator("ignore_empty")
url_validator = p.toolkit.get_validator("url_validator")


class PDFView(p.SingletonPlugin):
'''This plugin makes views of PDF resources, using an <object> tag'''
"""This plugin makes views of PDF resources, using an <object> tag"""

p.implements(p.IConfigurer, inherit=True)
p.implements(p.IResourceView, inherit=True)

def update_config(self, config):
p.toolkit.add_template_directory(config, 'theme/templates')
p.toolkit.add_template_directory(config, "theme/templates")

def info(self):
return {'name': 'pdf_view',
'title': p.toolkit._('PDF'),
'icon': 'file-pdf-o',
'schema': {'pdf_url': [ignore_empty, text_type]},
'iframed': False,
'always_available': False,
'default_title': p.toolkit._('PDF'),
}
return {
"name": "pdf_view",
"title": p.toolkit._("PDF"),
"icon": "file-pdf-o",
"schema": {"pdf_url": [ignore_empty, url_validator]},
"iframed": False,
"always_available": False,
"default_title": p.toolkit._("PDF"),
}

def can_view(self, data_dict):
return (data_dict['resource'].get('format', '').lower() == 'pdf')
return data_dict["resource"].get("format", "").lower() == "pdf"

def view_template(self, context, data_dict):
return 'pdf_view.html'
return "pdf_view.html"

def form_template(self, context, data_dict):
return 'pdf_form.html'
return "pdf_form.html"
35 changes: 20 additions & 15 deletions ckanext/pdfview/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
from ckan.plugins import toolkit


@pytest.mark.ckan_config('ckan.views.default_views', '')
@pytest.mark.ckan_config('ckan.plugins', 'pdf_view')
@pytest.mark.usefixtures('clean_db', 'with_plugins')
@pytest.mark.ckan_config("ckan.views.default_views", "")
@pytest.mark.ckan_config("ckan.plugins", "pdf_view")
@pytest.mark.usefixtures("clean_db", "with_plugins")
def test_view_shown_on_resource_page_with_pdf_url(app):

dataset = factories.Dataset()
resource = factories.Resource(package_id=dataset['id'],
format='pdf')
resource = factories.Resource(package_id=dataset["id"], format="pdf")
resource_view = factories.ResourceView(
resource_id=resource['id'],
view_type='pdf_view',
pdf_url='https://example/document.pdf')
resource_id=resource["id"],
view_type="pdf_view",
pdf_url="https://example/document.pdf",
)

if toolkit.check_ckan_version("2.9"):
url = toolkit.url_for('{}_resource.read'.format(dataset['type']),
id=dataset['name'], resource_id=resource['id'])
url = toolkit.url_for(
"{}_resource.read".format(dataset["type"]),
id=dataset["name"],
resource_id=resource["id"],
)
else:
url = toolkit.url_for(controller='package',
action='resource_read',
id=resource_view['package_id'],
resource_id=resource['id'])
url = toolkit.url_for(
controller="package",
action="resource_read",
id=resource_view["package_id"],
resource_id=resource["id"],
)

response = app.get(url)

assert 'https://example/document.pdf' in response.body
assert "https://example/document.pdf" in response.body

0 comments on commit 3acd4a5

Please sign in to comment.