Skip to content

Commit

Permalink
More robust endpoint handling
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Sep 1, 2020
1 parent db98f9b commit 519d353
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
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 update_config(self, config):
def get_helpers(self):
return {
'helper_available': utils.helper_available,
'dcat_get_endpoint': utils.get_endpoint,
}

# IActions
Expand Down
2 changes: 1 addition & 1 deletion ckanext/dcat/templates/home/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% ckan_extends %}
{% block links %}
{{ super() }}
{% with endpoint='dcat_catalog' if h.ckan_version() < '2.9' else 'dcat.read_catalog' %}
{% 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) }}"/>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/dcat/templates/package/read_base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% ckan_extends %}
{% block links %}
{{ super() }}
{% with endpoint='dcat_dataset' if h.ckan_version() < '2.9' else 'dcat.read_dataset' %}
{% 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) }}"/>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/dcat/templates/package/search.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% ckan_extends %}
{% block links %}
{{ super() }}
{% with endpoint='dcat_catalog' if h.ckan_version() < '2.9' else 'dcat.read_catalog' %}
{% 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) }}"/>
Expand Down
7 changes: 7 additions & 0 deletions ckanext/dcat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,10 @@ def read_catalog_page(_format):
response.headers['Content-type'] = CONTENT_TYPES[_format]

return response


def get_endpoint(_type='dataset'):
if toolkit.check_ckan_version(min_version='2.9'):
return 'dcat.read_dataset' if _type == 'dataset' else 'dcat.read_catalog'
else:
return 'dcat_dataset' if _type == 'dataset' else 'dcat_catalog'

0 comments on commit 519d353

Please sign in to comment.