Skip to content

Commit

Permalink
Refactor the way routes are made.
Browse files Browse the repository at this point in the history
Atramhasis was duplicating a lot of routes declared
in pyramid_skosprovider and these conflicts caused
issues because the regex path params which use .*
would consume a bunch of routes which it should not.

Issue #903
  • Loading branch information
Wim-De-Clercq committed Jul 30, 2024
1 parent 7ea582c commit 8841126
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 152 deletions.
5 changes: 4 additions & 1 deletion atramhasis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def includeme(config):
for key, value in DEFAULT_SETTINGS.items():
if key not in settings:
settings[key] = value
# Regexes in path params clash with this validation.
settings["pyramid_openapi3.enable_endpoint_validation"] = False
configure_session(config)
config.include('pyramid_jinja2')
config.include('pyramid_tm')
Expand All @@ -44,9 +46,10 @@ def includeme(config):
config.include('pyramid_rewrite')
config.include("pyramid_openapi3")
config.include('atramhasis.routes')
# pyramid_skosprovider must be included after the atramhasis routes
# because it contains a
config.include('pyramid_skosprovider')
config.include('atramhasis.cache')
config.scan('pyramid_skosprovider')

config.add_translation_dirs('atramhasis:locale/')

Expand Down
16 changes: 8 additions & 8 deletions atramhasis/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ paths:
description: The identifier for a certain concept or collection.
required: true
schema:
type: integer
type: string
responses:
200:
description: The concept was found in the conceptscheme.
Expand Down Expand Up @@ -172,7 +172,7 @@ paths:
description: The identifier for a certain concept or collection.
required: true
schema:
type: integer
type: string
requestBody:
required: true
description: Data to create concept or collection
Expand Down Expand Up @@ -222,7 +222,7 @@ paths:
description: The identifier for a certain concept or collection.
required: true
schema:
type: integer
type: string

responses:
200:
Expand Down Expand Up @@ -692,7 +692,7 @@ paths:
description: The identifier for a certain concept or collection.
required: true
schema:
type: integer
type: string
- name: language
in: query
description: Returns the label with the corresponding language-tag if present.
Expand Down Expand Up @@ -748,7 +748,7 @@ paths:
description: The identifier for a certain concept or collection.
required: true
schema:
type: integer
type: string
responses:
200:
description: The concept/collection was found in the conceptscheme.
Expand Down Expand Up @@ -900,7 +900,7 @@ components:
type: object
properties:
id:
type: integer
type: string
Label:
type: object
properties:
Expand Down Expand Up @@ -952,7 +952,7 @@ components:
type: object
properties:
id:
type: integer
type: string
type:
type: string
labels:
Expand Down Expand Up @@ -990,7 +990,7 @@ components:
- type: object
properties:
id:
type: integer
type: string
uri:
type: string
ConceptTree:
Expand Down
6 changes: 3 additions & 3 deletions atramhasis/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def _add_provider(graph, provider, dataseturi, request):
graph.add((dataseturi, VOID.subset, pd))
graph.add((pd, DCTERMS.identifier, Literal(pid)))
graph.add((pd, VOID.rootResource, URIRef(provider.concept_scheme.uri)))
graph.add((pd, FOAF.homepage, URIRef(request.route_url('conceptscheme', scheme_id=pid))))
graph.add((pd, FOAF.homepage, URIRef(request.route_url('skosprovider.conceptscheme', scheme_id=pid))))
_add_labels(graph, provider.concept_scheme, pd)
_add_metadataset(graph, pd, metadataset)
fmap = [
('rdf', FORMATS.RDF_XML, 'atramhasis.rdf_full_export_ext'),
('ttl', FORMATS.Turtle, 'atramhasis.rdf_full_export_turtle_ext')
('rdf', FORMATS.RDF_XML, 'skosprovider.conceptscheme.cs.rdf'),
('ttl', FORMATS.Turtle, 'skosprovider.conceptscheme.cs.ttl')
]
for f in fmap:
graph.add((pd, VOID.feature, f[1]))
Expand Down
66 changes: 16 additions & 50 deletions atramhasis/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,21 @@ def includeme(config):
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route("sitemap", "/sitemap_index.xml")

# APIs with extensions instead of accept headers
config.add_route('atramhasis.rdf_void_turtle_ext', pattern='/void.ttl', accept='text/turtle')
config.add_route('atramhasis.rdf_full_export_ext', pattern='/conceptschemes/{scheme_id}/c.rdf')
config.add_route('atramhasis.rdf_full_export_turtle_ext', pattern='/conceptschemes/{scheme_id}/c.ttl')
config.add_route('atramhasis.rdf_conceptscheme_export_ext', pattern='/conceptschemes/{scheme_id}.rdf')
config.add_route('atramhasis.rdf_conceptscheme_export_turtle_ext', pattern='/conceptschemes/{scheme_id}.ttl')
config.add_route('atramhasis.rdf_individual_export_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.rdf')
config.add_route('atramhasis.rdf_individual_export_turtle_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.ttl')
config.add_route('atramhasis.rdf_conceptscheme_jsonld_ext', pattern='/conceptschemes/{scheme_id}.jsonld')
config.add_route('atramhasis.rdf_individual_jsonld_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.jsonld')
config.add_route('skosprovider.conceptscheme.cs.rdf', pattern='/conceptschemes/{scheme_id}/c.rdf')
config.add_route('skosprovider.conceptscheme.cs.ttl', pattern='/conceptschemes/{scheme_id}/c.ttl')
config.add_route('skosprovider.conceptscheme.rdf', pattern='/conceptschemes/{scheme_id}.rdf')
config.add_route('skosprovider.conceptscheme.ttl', pattern='/conceptschemes/{scheme_id}.ttl')
config.add_route('skosprovider.conceptscheme.csv', pattern='/conceptschemes/{scheme_id}/c.csv')
config.add_route('skosprovider.c.rdf', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.rdf')
config.add_route('skosprovider.c.ttl', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.ttl')

config.add_route('conceptschemes', pattern='/conceptschemes', accept='text/html', request_method="GET")
config.add_route('conceptscheme', pattern='/conceptschemes/{scheme_id}', accept='text/html', request_method="GET")
config.add_route('concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}', accept='text/html',
request_method="GET")
config.add_route('search_result', pattern='/conceptschemes/{scheme_id}/c', accept='text/html')
config.add_route('scheme_root', pattern='/conceptschemes/{scheme_id}/c/', accept='text/html')
# tree
config.add_route('scheme_tree_html', pattern='/conceptschemes/{scheme_id}/tree', accept='text/html')
config.add_route('scheme_tree', pattern='/conceptschemes/{scheme_id}/tree', accept='application/json')

config.add_route('search_result_export', pattern='/conceptschemes/{scheme_id}/c.csv')
config.add_route('atramhasis.edit_conceptscheme', pattern='/conceptschemes/{scheme_id}',
accept='application/json', request_method='PUT')
config.add_route('atramhasis.get_conceptscheme', pattern='/conceptschemes/{scheme_id}', accept='application/json')
config.add_route('atramhasis.get_conceptschemes', pattern='/conceptschemes', accept='application/json')
config.add_route('atramhasis.get_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/json', request_method="GET")
config.add_route('atramhasis.add_concept', pattern='/conceptschemes/{scheme_id}/c', accept='application/json',
request_method="POST")
config.add_route('atramhasis.edit_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/json', request_method="PUT")
config.add_route('atramhasis.delete_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/json', request_method="DELETE")
# language
config.add_route('atramhasis.list_languages', pattern='/languages', accept='application/json',
request_method="GET")
config.add_route('atramhasis.get_language', pattern='/languages/{l_id}', accept='application/json',
Expand All @@ -68,33 +51,16 @@ def includeme(config):
config.add_route('atramhasis.delete_language', pattern='/languages/{l_id}', accept='application/json',
request_method="DELETE")
config.add_route('locale', '/locale')
config.add_route('labeltypes', '/labeltypes', accept='application/json', request_method="GET")
config.add_route('notetypes', '/notetypes', accept='application/json', request_method="GET")

# admin
config.add_route('admin', '/admin')
config.add_route('scheme_tree_invalidate', pattern='/admin/tree/invalidate/{scheme_id}', accept='application/json')
config.add_route('tree_invalidate', pattern='/admin/tree/invalidate', accept='application/json')

config.add_route('atramhasis.rdf_full_export_turtle', pattern='/conceptschemes/{scheme_id}/c', accept='text/turtle')
config.add_route('atramhasis.rdf_full_export_turtle_x', pattern='/conceptschemes/{scheme_id}/c',
accept='application/x-turtle')
config.add_route('atramhasis.rdf_full_export', pattern='/conceptschemes/{scheme_id}/c',
accept='application/rdf+xml')
config.add_route('atramhasis.rdf_conceptscheme_export', pattern='/conceptschemes/{scheme_id}',
accept='application/rdf+xml')
config.add_route('atramhasis.rdf_conceptscheme_export_turtle', pattern='/conceptschemes/{scheme_id}',
accept='text/turtle')
config.add_route('atramhasis.rdf_conceptscheme_export_turtle_x', pattern='/conceptschemes/{scheme_id}',
accept='application/x-turtle')
config.add_route('atramhasis.rdf_individual_export', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/rdf+xml')
config.add_route('atramhasis.rdf_individual_export_turtle', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='text/turtle')
config.add_route('atramhasis.rdf_individual_export_turtle_x', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/x-turtle')
config.add_route('atramhasis.rdf_conceptscheme_jsonld', pattern='/conceptschemes/{scheme_id}',
accept='application/ld+json')
config.add_route('atramhasis.rdf_individual_jsonld', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/ld+json')
# providers
config.add_route('atramhasis.providers', pattern='/providers')
config.add_route('atramhasis.provider', pattern='/providers/{id}')

# other
config.add_route('labeltypes', '/labeltypes', accept='application/json', request_method="GET")
config.add_route('notetypes', '/notetypes', accept='application/json', request_method="GET")
12 changes: 6 additions & 6 deletions atramhasis/templates/concept.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block head %}
{{ super() }}
<meta name="og:type" content="website" />
<meta name="og:url" content="{{ request.route_url('concept', scheme_id=scheme_id, c_id=concept.concept_id) }}" />
<meta name="og:url" content="{{ request.route_url('skosprovider.c', scheme_id=scheme_id, c_id=concept.concept_id) }}" />
<meta name="og:title" content="{{ concept.label(locale).label|safe }}" />
{% if concept.notes|length > 0 %}
<meta name="og:description" content="{{ concept.notes[0]|safe }}" />
Expand All @@ -13,7 +13,7 @@
{% if concept.notes|length > 0 %}
<meta name="twitter:description" content="{{ concept.notes[0]|safe }}" />
{% endif %}
<link rel="canonical" href="{{ request.route_url('concept', scheme_id=scheme_id, c_id=concept.concept_id) }}" />
<link rel="canonical" href="{{ request.route_url('skosprovider.c', scheme_id=scheme_id, c_id=concept.concept_id) }}" />
{% endblock %}
{% block html_title %}{{ concept.label(locale).label|title }}{% endblock %}

Expand All @@ -31,9 +31,9 @@
<div class="clearfix">
<ul class="downloadtop right">
<li>DOWNLOAD</li>
<li><a href="{{ request.route_path('atramhasis.rdf_individual_export_ext', scheme_id=scheme_id, c_id=concept.concept_id) }}">RDF/XML</a></li>
<li><a href="{{ request.route_path('atramhasis.rdf_individual_jsonld_ext', scheme_id=scheme_id, c_id=concept.concept_id) }}">JSON-LD</a></li>
<li><a href="{{ request.route_path('atramhasis.rdf_individual_export_turtle_ext', scheme_id=scheme_id, c_id=concept.concept_id) }}">N3/Turtle</a></li>
<li><a href="{{ request.route_path('skosprovider.c.rdf', scheme_id=scheme_id, c_id=concept.concept_id) }}">RDF/XML</a></li>
<li><a href="{{ request.route_path('skosprovider.c.jsonld', scheme_id=scheme_id, c_id=concept.concept_id) }}">JSON-LD</a></li>
<li><a href="{{ request.route_path('skosprovider.c.ttl', scheme_id=scheme_id, c_id=concept.concept_id) }}">N3/Turtle</a></li>
</ul>
</div>
{% if concept %}
Expand All @@ -53,7 +53,7 @@
<dd class="word-wrap-element"><a href="{{ concept.uri }}">{{ concept.uri }}</a></dd>
{% endif %}
<dt>schema</dt>
<dd><a href="{{ request.route_path('conceptscheme', scheme_id=scheme_id) }}">{{ get_conceptscheme_label(concept.conceptscheme, request.locale_name) }}</a></dd>
<dd><a href="{{ request.route_path('skosprovider.conceptscheme', scheme_id=scheme_id) }}">{{ get_conceptscheme_label(concept.conceptscheme, request.locale_name) }}</a></dd>
{% if concept.labels %}
{{ print_labels(concept.labels) }}
{% endif %}
Expand Down
14 changes: 7 additions & 7 deletions atramhasis/templates/conceptscheme.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block head %}
{{ super() }}
<meta name="og:type" content="website" />
<meta name="og:url" content="{{ request.route_url('conceptscheme', scheme_id=conceptscheme.scheme_id) }}" />
<meta name="og:url" content="{{ request.route_url('skosprovider.conceptscheme', scheme_id=conceptscheme.scheme_id) }}" />
<meta name="og:title" content="{{ conceptscheme.title }}" />
{% if conceptscheme.notes|length > 0 %}
<meta name="og:description" content="{{ conceptscheme.notes[0]|safe }}" />
Expand All @@ -13,7 +13,7 @@
{% if conceptscheme.notes|length > 0 %}
<meta name="twitter:description" content="{{ conceptscheme.notes[0]|safe }}" />
{% endif %}
<link rel="canonical" href="{{ request.route_url('conceptscheme', scheme_id=conceptscheme.scheme_id) }}" />
<link rel="canonical" href="{{ request.route_url('skosprovider.conceptscheme', scheme_id=conceptscheme.scheme_id) }}" />
{% endblock %}
{% block html_title %}{{ conceptscheme.title }}{% endblock %}

Expand All @@ -29,11 +29,11 @@
<div class="clearfix">
<ul class="downloadtop right">
<li>DOWNLOAD</li>
<li><a title="Download the scheme and it's top concepts in RDF/XML format." href="{{request.route_path('atramhasis.rdf_conceptscheme_export_ext', scheme_id=conceptscheme.scheme_id)}}">RDF/XML</a></li>
<li><a title="Download the scheme and it's top concepts in JSON-LD format." href="{{request.route_path('atramhasis.rdf_conceptscheme_jsonld_ext', scheme_id=conceptscheme.scheme_id)}}">JSON-LD</a></li>
<li><a title="Download the scheme and it's top concepts in N3/Turle format." href="{{request.route_path('atramhasis.rdf_conceptscheme_export_turtle_ext', scheme_id=conceptscheme.scheme_id)}}">N3/Turtle</a></li>
<li><a title="Download the scheme and all it's concepts and collections in RDF/XML format." href="{{request.route_path('atramhasis.rdf_full_export_ext', scheme_id=conceptscheme.scheme_id)}}">Full RDF/XML</a></li>
<li><a title="Download the scheme and all it's concepts and collections in N3/Turtle format." href="{{request.route_path('atramhasis.rdf_full_export_turtle_ext', scheme_id=conceptscheme.scheme_id)}}">Full N3/Turtle</a></li>
<li><a title="Download the scheme and it's top concepts in RDF/XML format." href="{{request.route_path('skosprovider.conceptscheme.rdf', scheme_id=conceptscheme.scheme_id)}}">RDF/XML</a></li>
<li><a title="Download the scheme and it's top concepts in JSON-LD format." href="{{request.route_path('skosprovider.conceptscheme.jsonld', scheme_id=conceptscheme.scheme_id)}}">JSON-LD</a></li>
<li><a title="Download the scheme and it's top concepts in N3/Turle format." href="{{request.route_path('skosprovider.conceptscheme.ttl', scheme_id=conceptscheme.scheme_id)}}">N3/Turtle</a></li>
<li><a title="Download the scheme and all it's concepts and collections in RDF/XML format." href="{{request.route_path('skosprovider.conceptscheme.cs.rdf', scheme_id=conceptscheme.scheme_id)}}">Full RDF/XML</a></li>
<li><a title="Download the scheme and all it's concepts and collections in N3/Turtle format." href="{{request.route_path('skosprovider.conceptscheme.cs.ttl', scheme_id=conceptscheme.scheme_id)}}">Full N3/Turtle</a></li>
<li><a title="Open a printable scheme tree and all it's concepts." href="{{request.route_path('scheme_tree_html', scheme_id=conceptscheme.scheme_id)}}">Printable Tree</a></li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion atramhasis/templates/conceptschemes.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="row">
<h3 class="concept">{% trans %}select_scheme{% endtrans %}</h3>
{% for item in conceptschemes %}
<div class="large-3 large-3-pad columns result-grid"><a href="{{ request.route_path('conceptscheme', scheme_id=item.id) }}"><h5>{{ get_conceptscheme_label(item.conceptscheme, request.locale_name) }}</h5> <span> [ ID : {{ item.id }} ]</span><br><small>{{ item.type }}</small></a></div>
<div class="large-3 large-3-pad columns result-grid"><a href="{{ request.route_path('skosprovider.conceptscheme', scheme_id=item.id) }}"><h5>{{ get_conceptscheme_label(item.conceptscheme, request.locale_name) }}</h5> <span> [ ID : {{ item.id }} ]</span><br><small>{{ item.type }}</small></a></div>
{% endfor %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion atramhasis/templates/conceptschemes_overview.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="large-12 columns">
<div class="row" style="padding-top: 25px;">
{% for item in conceptschemes %}
<div class="large-3 large-3-pad columns result-grid"><a href="{{ request.route_path('conceptscheme', scheme_id=item.id) }}"><h5>{{ get_conceptscheme_label(item.conceptscheme, request.locale_name) }}</h5> <span> [ ID : {{ item.id }} ]</span><br><small>{{ item.type }}</small></a></div>
<div class="large-3 large-3-pad columns result-grid"><a href="{{ request.route_path('skosprovider.conceptscheme', scheme_id=item.id) }}"><h5>{{ get_conceptscheme_label(item.conceptscheme, request.locale_name) }}</h5> <span> [ ID : {{ item.id }} ]</span><br><small>{{ item.type }}</small></a></div>
{% endfor %}
</div>
</div>
2 changes: 1 addition & 1 deletion atramhasis/templates/header-page.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<select id="scheme">
<option value="" selected>{% trans %}select_scheme{% endtrans %}</option>
{% for item in conceptschemes %}
<option {% if item.id == scheme_id %} selected="selected" {% endif %} value="{{ request.route_path('search_result', scheme_id=item.id) }}">
<option {% if item.id == scheme_id %} selected="selected" {% endif %} value="{{ request.route_path('skosprovider.conceptscheme.cs', scheme_id=item.id) }}">
{{ get_conceptscheme_label(item.conceptscheme, request.locale_name) }}
</option>
{% endfor %}
Expand Down
Loading

0 comments on commit 8841126

Please sign in to comment.