diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2f7155c..28c88b12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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' @@ -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 }} @@ -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: @@ -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 diff --git a/ckanext/dcat/harvesters/_json.py b/ckanext/dcat/harvesters/_json.py index 8332eeb6..5eea7ac0 100644 --- a/ckanext/dcat/harvesters/_json.py +++ b/ckanext/dcat/harvesters/_json.py @@ -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 @@ -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'] diff --git a/ckanext/dcat/harvesters/rdf.py b/ckanext/dcat/harvesters/rdf.py index d67681b8..05026f4f 100644 --- a/ckanext/dcat/harvesters/rdf.py +++ b/ckanext/dcat/harvesters/rdf.py @@ -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 @@ -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 = {} diff --git a/ckanext/dcat/processors.py b/ckanext/dcat/processors.py index cc514107..f7218219 100644 --- a/ckanext/dcat/processors.py +++ b/ckanext/dcat/processors.py @@ -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: diff --git a/ckanext/dcat/profiles.py b/ckanext/dcat/profiles.py index d1479717..7cd6e50e 100644 --- a/ckanext/dcat/profiles.py +++ b/ckanext/dcat/profiles.py @@ -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/") @@ -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 @@ -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): @@ -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)) diff --git a/ckanext/dcat/templates/home/index.html b/ckanext/dcat/templates/home/index.html index 6bc53755..d92671e4 100644 --- a/ckanext/dcat/templates/home/index.html +++ b/ckanext/dcat/templates/home/index.html @@ -2,9 +2,9 @@ {% block links %} {{ super() }} {% with endpoint=h.dcat_get_endpoint('catalog') %} - - - - + + + + {% endwith %} {% endblock -%} diff --git a/ckanext/dcat/templates/package/read_base.html b/ckanext/dcat/templates/package/read_base.html index 7811a2ec..ea178d06 100644 --- a/ckanext/dcat/templates/package/read_base.html +++ b/ckanext/dcat/templates/package/read_base.html @@ -2,10 +2,10 @@ {% block links %} {{ super() }} {% with endpoint=h.dcat_get_endpoint('dataset') %} - - - - + + + + {% endwith %} {% endblock -%} {% block body_extras %} diff --git a/ckanext/dcat/templates/package/search.html b/ckanext/dcat/templates/package/search.html index 6bc53755..d92671e4 100644 --- a/ckanext/dcat/templates/package/search.html +++ b/ckanext/dcat/templates/package/search.html @@ -2,9 +2,9 @@ {% block links %} {{ super() }} {% with endpoint=h.dcat_get_endpoint('catalog') %} - - - - + + + + {% endwith %} {% endblock -%} diff --git a/ckanext/dcat/tests/test_blueprints.py b/ckanext/dcat/tests/test_blueprints.py index 02707b37..5d10a081 100644 --- a/ckanext/dcat/tests/test_blueprints.py +++ b/ckanext/dcat/tests/test_blueprints.py @@ -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): @@ -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(): diff --git a/ckanext/dcat/urls.py b/ckanext/dcat/urls.py new file mode 100644 index 00000000..7b4dbc52 --- /dev/null +++ b/ckanext/dcat/urls.py @@ -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)