Skip to content

Commit

Permalink
Don't try to render the DCAT endpoints if turned off by config
Browse files Browse the repository at this point in the history
Fixes #230

The templates were always trying to create the endpoints URL, even if
the routes were not registered in the blueprint because it was set to
ckanext.dcat.enable_rdf_endpoints = False
  • Loading branch information
amercader committed Oct 4, 2023
1 parent 33498df commit e118fc4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ckanext/dcat/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def read_catalog(_format=None, package_type=None):
def read_dataset(_id, _format=None, package_type=None):
return utils.read_dataset_page(_id, _format)

if toolkit.asbool(config.get(utils.ENABLE_RDF_ENDPOINTS_CONFIG, True)):

if utils.endpoints_enabled():

# requirements={'_format': 'xml|rdf|n3|ttl|jsonld'}
dcat.add_url_rule(config.get('ckanext.dcat.catalog_endpoint',
Expand Down
1 change: 1 addition & 0 deletions ckanext/dcat/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def get_helpers(self):
return {
'helper_available': utils.helper_available,
'dcat_get_endpoint': utils.get_endpoint,
'dcat_endpoints_enabled': utils.endpoints_enabled,
}

# IActions
Expand Down
16 changes: 10 additions & 6 deletions ckanext/dcat/templates/package/read_base.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{% ckan_extends %}
{% 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', _external=True) }}"/>
<link rel="alternate" type="text/turtle" 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 %}

{% if h.dcat_endpoints_enabled() %}
{% with endpoint=h.dcat_get_endpoint('dataset') %}
<link rel="alternate" type="text/n3" href="{{ h.url_for(endpoint, _id=pkg.id, _format='n3', _external=True) }}"/>
<link rel="alternate" type="text/turtle" 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 %}
{% endif %}
{% endblock -%}
{% block body_extras %}
{{ super() }}
Expand Down
4 changes: 4 additions & 0 deletions ckanext/dcat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,5 +452,9 @@ def read_catalog_page(_format):
return response


def endpoints_enabled():
return toolkit.asbool(config.get(ENABLE_RDF_ENDPOINTS_CONFIG, True))


def get_endpoint(_type='dataset'):
return 'dcat.read_dataset' if _type == 'dataset' else 'dcat.read_catalog'

0 comments on commit e118fc4

Please sign in to comment.