Skip to content

Commit

Permalink
Merge pull request ckan#208 from avdata99/2.10-support
Browse files Browse the repository at this point in the history
Support CKAN 2.10
  • Loading branch information
amercader authored Apr 22, 2022
2 parents 56eb245 + cb7e209 commit d616db8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 57 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: '3.6'
Expand All @@ -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 All @@ -44,7 +44,7 @@ jobs:
CKAN_REDIS_URL: redis://redis:6379/1

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install requirements
run: |
pip install -r requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions ckanext/dcat/harvesters/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ckan import logic
from ckan import plugins as p
from ckanext.harvest.model import HarvestObject, HarvestObjectExtra

from ckanext.harvest.logic.schema import unicode_safe
from ckanext.dcat import converters
from ckanext.dcat.harvesters.base import DCATHarvester

Expand Down Expand Up @@ -263,7 +263,7 @@ def import_stage(self, harvest_object):

# We need to explicitly provide a package ID
package_dict['id'] = str(uuid.uuid4())
package_schema['id'] = [str]
package_schema['id'] = [unicode_safe]

# Save reference to the package on the object
harvest_object.package_id = package_dict['id']
Expand Down
6 changes: 2 additions & 4 deletions ckanext/dcat/harvesters/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
import ckan.lib.plugins as lib_plugins

from ckanext.harvest.model import HarvestObject, HarvestObjectExtra

from ckanext.harvest.logic.schema import unicode_safe
from ckanext.dcat.harvesters.base import DCATHarvester

from ckanext.dcat.processors import RDFParserException, RDFParser

from ckanext.dcat.interfaces import IDCATRDFHarvester


Expand Down Expand Up @@ -379,7 +377,7 @@ def import_stage(self, harvest_object):

# We need to explicitly provide a package ID
dataset['id'] = str(uuid.uuid4())
package_schema['id'] = [str]
package_schema['id'] = [unicode_safe]

harvester_tmp_dict = {}

Expand Down
7 changes: 0 additions & 7 deletions ckanext/dcat/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,6 @@ def graph_from_dataset(self, dataset_dict):
Returns the reference to the dataset, which will be an rdflib URIRef.
'''

uri_value = dataset_dict.get('uri')
if not uri_value:
for extra in dataset_dict.get('extras', []):
if extra['key'] == 'uri':
uri_value = extra['value']
break

dataset_ref = URIRef(dataset_uri(dataset_dict))

for profile_class in self._profiles:
Expand Down
10 changes: 5 additions & 5 deletions ckanext/dcat/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from ckan.model.license import LicenseRegister
from ckan.plugins import toolkit
from ckan.lib.munge import munge_tag
from ckan.lib.helpers import url_for

from ckanext.dcat.urls import url_for
from ckanext.dcat.utils import resource_uri, publisher_uri_organization_fallback, DCAT_EXPOSE_SUBCATALOGS, DCAT_CLEAN_TAGS

DCT = Namespace("http://purl.org/dc/terms/")
Expand Down Expand Up @@ -459,6 +458,7 @@ def _access_rights(self, subject, predicate):
if isinstance(obj, BNode) and self._object(obj, RDF.type) == DCT.RightsStatement:
result = self._object_value(obj, RDFS.label)
elif isinstance(obj, Literal) or isinstance(obj, URIRef):
# unicode_safe not include Literal or URIRef
result = six.text_type(obj)
return result

Expand Down Expand Up @@ -1443,9 +1443,9 @@ def _basic_fields_graph(self, dataset_ref, dataset_dict):
self._add_date_triples_from_dict(dataset_dict, dataset_ref, items)

# Dataset URL
dataset_url = url_for('dataset_read',
dataset_url = url_for('dataset.read',
id=dataset_dict['name'],
qualified=True)
_external=True)
self.g.add((dataset_ref, SCHEMA.url, Literal(dataset_url)))

def _catalog_graph(self, dataset_ref, dataset_dict):
Expand All @@ -1461,7 +1461,7 @@ def _groups_graph(self, dataset_ref, dataset_dict):
group_url = url_for(controller='group',
action='read',
id=group.get('id'),
qualified=True)
_external=True)
about = BNode()

self.g.add((about, RDF.type, SCHEMA.Thing))
Expand Down
8 changes: 4 additions & 4 deletions ckanext/dcat/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{% block links %}
{{ super() }}
{% with endpoint=h.dcat_get_endpoint('catalog') %}
<link rel="alternate" type="text/n3" href="{{ h.url_for(endpoint, _format='n3', qualified=True) }}"/>
<link rel="alternate" type="text/ttl" href="{{ h.url_for(endpoint, _format='ttl', qualified=True) }}"/>
<link rel="alternate" type="application/rdf+xml" href="{{ h.url_for(endpoint, _format='xml', qualified=True) }}"/>
<link rel="alternate" type="application/ld+json" href="{{ h.url_for(endpoint, _format='jsonld', qualified=True) }}"/>
<link rel="alternate" type="text/n3" href="{{ h.url_for(endpoint, _format='n3', _external=True) }}"/>
<link rel="alternate" type="text/ttl" href="{{ h.url_for(endpoint, _format='ttl', _external=True) }}"/>
<link rel="alternate" type="application/rdf+xml" href="{{ h.url_for(endpoint, _format='xml', _external=True) }}"/>
<link rel="alternate" type="application/ld+json" href="{{ h.url_for(endpoint, _format='jsonld', _external=True) }}"/>
{% endwith %}
{% endblock -%}
8 changes: 4 additions & 4 deletions ckanext/dcat/templates/package/read_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{% block links %}
{{ super() }}
{% with endpoint=h.dcat_get_endpoint('dataset') %}
<link rel="alternate" type="text/n3" href="{{ h.url_for(endpoint, _id=pkg.id, _format='n3', qualified=True) }}"/>
<link rel="alternate" type="text/ttl" href="{{ h.url_for(endpoint, _id=pkg.id, _format='ttl', qualified=True) }}"/>
<link rel="alternate" type="application/rdf+xml" href="{{ h.url_for(endpoint, _id=pkg.id, _format='xml', qualified=True) }}"/>
<link rel="alternate" type="application/ld+json" href="{{ h.url_for(endpoint, _id=pkg.id, _format='jsonld', qualified=True) }}"/>
<link rel="alternate" type="text/n3" href="{{ h.url_for(endpoint, _id=pkg.id, _format='n3', _external=True) }}"/>
<link rel="alternate" type="text/ttl" href="{{ h.url_for(endpoint, _id=pkg.id, _format='ttl', _external=True) }}"/>
<link rel="alternate" type="application/rdf+xml" href="{{ h.url_for(endpoint, _id=pkg.id, _format='xml', _external=True) }}"/>
<link rel="alternate" type="application/ld+json" href="{{ h.url_for(endpoint, _id=pkg.id, _format='jsonld', _external=True) }}"/>
{% endwith %}
{% endblock -%}
{% block body_extras %}
Expand Down
8 changes: 4 additions & 4 deletions ckanext/dcat/templates/package/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{% block links %}
{{ super() }}
{% with endpoint=h.dcat_get_endpoint('catalog') %}
<link rel="alternate" type="text/n3" href="{{ h.url_for(endpoint, _format='n3', qualified=True) }}"/>
<link rel="alternate" type="text/ttl" href="{{ h.url_for(endpoint, _format='ttl', qualified=True) }}"/>
<link rel="alternate" type="application/rdf+xml" href="{{ h.url_for(endpoint, _format='xml', qualified=True) }}"/>
<link rel="alternate" type="application/ld+json" href="{{ h.url_for(endpoint, _format='jsonld', qualified=True) }}"/>
<link rel="alternate" type="text/n3" href="{{ h.url_for(endpoint, _format='n3', _external=True) }}"/>
<link rel="alternate" type="text/ttl" href="{{ h.url_for(endpoint, _format='ttl', _external=True) }}"/>
<link rel="alternate" type="application/rdf+xml" href="{{ h.url_for(endpoint, _format='xml', _external=True) }}"/>
<link rel="alternate" type="application/ld+json" href="{{ h.url_for(endpoint, _format='jsonld', _external=True) }}"/>
{% endwith %}
{% endblock -%}
24 changes: 1 addition & 23 deletions ckanext/dcat/tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from ckan import plugins as p

from rdflib import Graph
from ckantoolkit import url_for as core_url_for
from ckantoolkit.tests import factories

from ckanext.dcat.processors import RDFParser
from ckanext.dcat.profiles import RDF, DCAT
from ckanext.dcat.processors import HYDRA
from ckanext.dcat.urls import url_for


def _sort_query_params(url):
Expand All @@ -30,28 +30,6 @@ def _sort_query_params(url):
encoded_qs, parts.fragment)
)


def url_for(*args, **kwargs):

if not p.toolkit.check_ckan_version(min_version='2.9'):

external = kwargs.pop('_external', False)
if external is not None:
kwargs['qualified'] = external

if len(args) and args[0] == 'dcat.read_dataset':
return core_url_for('dcat_dataset', **kwargs)
elif len(args) and args[0] == 'dcat.read_catalog':
return core_url_for('dcat_catalog', **kwargs)
elif len(args) and args[0] == 'dataset.new':
return core_url_for(controller='package', action='new', **kwargs)
elif len(args) and args[0] == 'dataset.read':
return core_url_for(controller='package', action='read', **kwargs)


return core_url_for(*args, **kwargs)


@pytest.mark.usefixtures('with_plugins', 'clean_db', 'clean_index')
class TestEndpoints():

Expand Down
23 changes: 23 additions & 0 deletions ckanext/dcat/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import six
from ckan.plugins import toolkit as tk
from ckantoolkit import url_for as core_url_for


def url_for(*args, **kwargs):

if not tk.check_ckan_version(min_version='2.9'):

external = kwargs.pop('_external', False)
if external is not None and 'qualified' not in kwargs:
kwargs['qualified'] = external

if len(args) and args[0] == 'dcat.read_dataset':
return core_url_for('dcat_dataset', **kwargs)
elif len(args) and args[0] == 'dcat.read_catalog':
return core_url_for('dcat_catalog', **kwargs)
elif len(args) and args[0] == 'dataset.new':
return core_url_for(controller='package', action='new', **kwargs)
elif len(args) and args[0] == 'dataset.read':
return core_url_for(controller='package', action='read', **kwargs)

return core_url_for(*args, **kwargs)

0 comments on commit d616db8

Please sign in to comment.