Skip to content

Commit

Permalink
Merge d7f88fb into ca58c9f
Browse files Browse the repository at this point in the history
  • Loading branch information
cedrikv committed Oct 30, 2020
2 parents ca58c9f + d7f88fb commit e840ed2
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 20 deletions.
3 changes: 3 additions & 0 deletions atramhasis/audit.py
Expand Up @@ -16,12 +16,15 @@ def _origin_from_request(request):
return 'HTML'
elif 'application/json' in request.accept:
return 'REST'
elif 'application/ld+json' in request.accept:
return 'RDF'
else:
return None


def _origin_from_response(response):
if response.content_type == 'application/rdf+xml' \
or response.content_type == 'application/ld+json' \
or response.content_type == 'text/turtle' \
or response.content_type == 'application/x-turtle':
return 'RDF'
Expand Down
6 changes: 6 additions & 0 deletions atramhasis/routes.py
Expand Up @@ -27,6 +27,8 @@ def includeme(config):
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('conceptschemes', pattern='/conceptschemes', accept='text/html', request_method="GET")
config.add_route('conceptscheme', pattern='/conceptschemes/{scheme_id}', accept='text/html', request_method="GET")
Expand Down Expand Up @@ -83,3 +85,7 @@ def includeme(config):
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')
7 changes: 4 additions & 3 deletions atramhasis/templates/concept.jinja2
Expand Up @@ -3,19 +3,19 @@
{{ 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:title" content="{{ concept.label(request.locale_name).label|safe }}" />
<meta name="og:title" content="{{ concept.label(locale).label|safe }}" />
{% if concept.notes|length > 0 %}
<meta name="og:description" content="{{ concept.notes[0]|safe }}" />
{% endif %}
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="{{ request.registry.settings['twitter.site']}}" />
<meta name="twitter:title" content="{{ concept.label(request.locale_name).label|safe }}" />
<meta name="twitter:title" content="{{ concept.label(locale).label|safe }}" />
{% 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) }}" />
{% endblock %}
{% block html_title %}{{ concept.label(request.locale_name).label|title }}{% endblock %}
{% block html_title %}{{ concept.label(locale).label|title }}{% endblock %}

{% from "macros.jinja2" import
render_relaties_lijst,
Expand All @@ -32,6 +32,7 @@
<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>
</ul>
</div>
Expand Down
1 change: 1 addition & 0 deletions atramhasis/templates/conceptscheme.jinja2
Expand Up @@ -30,6 +30,7 @@
<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>
Expand Down
19 changes: 13 additions & 6 deletions atramhasis/templates/header-page.jinja2
Expand Up @@ -22,7 +22,7 @@
<select id="scheme">
<option value="" selected>{% trans %}select_scheme{% endtrans %}</option>
{% for item in conceptschemes %}
<option value="{{ request.route_path('search_result', scheme_id=item.id) }}">
<option {% if item.id == scheme_id %} selected="selected" {% endif %} value="{{ request.route_path('search_result', scheme_id=item.id) }}">
{{ get_conceptscheme_label(item.conceptscheme, request.locale_name) }}
</option>
{% endfor %}
Expand All @@ -31,16 +31,23 @@
<li class="divider"></li>
<li>
<select id="ctype" name="ctype">
<option value="all" selected>{% trans %}select_type{% endtrans %}</option>
<option value="all">{% trans %}type_all{% endtrans %}</option>
<option value="concept">{% trans %}type_concept{% endtrans %}</option>
<option value="collection">{% trans %}type_collection{% endtrans %}</option>
<option value="all">{% trans %}select_type{% endtrans %}</option>
<option {% if ctype == 'all' %} selected="selected" {% endif %} value="all">{% trans %}type_all{% endtrans %}</option>
<option {% if ctype == 'concept' %} selected="selected" {% endif %} value="concept">{% trans %}type_concept{% endtrans %}</option>
<option {% if ctype == 'collection' %} selected="selected" {% endif %} value="collection">{% trans %}type_collection{% endtrans %}</option>
</select>
</li>
<li class="divider"></li>
<li class="has-form">
<div class="row collapse">
<div class="left"><input name="label" id="label" type="text" class="search-input-top" placeholder="{% trans %}search_for{% endtrans %} {% trans %}labels{% endtrans %}"/></div>
<div class="left">
<input {% if label is not none %} value="{{label}}" {% endif %}
name="label"
id="label"
type="text"
class="search-input-top"
placeholder="{% trans %}search_for{% endtrans %} {% trans %}labels{% endtrans %}"/>
</div>
<div class="left"><button type="submit"><span class="ico ico-mglass"></span></button></div>
</div>
</li>
Expand Down
2 changes: 1 addition & 1 deletion atramhasis/templates/search_result.jinja2
Expand Up @@ -15,7 +15,7 @@
</ul>
</div>
{%- for c in concepts %}
<div class="large-3 large-3-pad columns result-grid"><a href="{{ request.route_path('concept', scheme_id= scheme_id, c_id = c.id) }}"><h5>{{ c.label }}</h5> <span> [ ID : {{ c.id }} ]</span><br><small>{{ c.type }}</small></a></div>
<div class="large-3 large-3-pad columns result-grid"><a href="{{ request.route_path('concept', scheme_id= scheme_id, c_id = c.id) }}?ctype={{ctype}}&label={% if label is not none %}{{label}}{% endif %}"><h5>{{ c.label }}</h5> <span> [ ID : {{ c.id }} ]</span><br><small>{{ c.type }}</small></a></div>
{%- endfor %}
</div>
</div>
Expand Down
24 changes: 23 additions & 1 deletion atramhasis/views/rdf.py
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

import os

from pyramid import compat
from pyramid.renderers import render
from pyramid.response import Response, FileResponse
from pyramid.view import view_defaults, view_config
from pyramid_skosprovider.views import ProviderView
from skosprovider_rdf import utils

from atramhasis.errors import (
Expand Down Expand Up @@ -119,3 +121,23 @@ def rdf_individual_export_turtle(self):
response.body = graph.serialize(format='turtle')
response.content_disposition = 'attachment; filename="%s.ttl"' % (str(self.c_id),)
return response

@audit
@view_config(route_name='atramhasis.rdf_conceptscheme_jsonld', permission='view')
@view_config(route_name='atramhasis.rdf_conceptscheme_jsonld_ext', permission='view')
def get_conceptscheme_jsonld(self):
conceptscheme = ProviderView(self.request).get_conceptscheme_jsonld()
response = Response(content_type='application/ld+json')
response.text = compat.text_(render('skosjsonld', conceptscheme, self.request))
response.content_disposition = 'attachment; filename="%s.jsonld"' % (str(self.scheme_id),)
return response

@audit
@view_config(route_name='atramhasis.rdf_individual_jsonld', permission='view')
@view_config(route_name='atramhasis.rdf_individual_jsonld_ext', permission='view')
def get_concept(self):
concept = ProviderView(self.request).get_concept()
response = Response(content_type='application/ld+json')
response.text = compat.text_(render('skosjsonld', concept, self.request))
response.content_disposition = 'attachment; filename="%s.jsonld"' % (str(self.c_id),)
return response
19 changes: 13 additions & 6 deletions atramhasis/views/views.py
Expand Up @@ -151,6 +151,9 @@ def concept_view(self):
scheme_id = self.request.matchdict['scheme_id']
c_id = self.request.matchdict['c_id']
provider = self.request.skos_registry.get_provider(scheme_id)
label = self._read_request_param('label')
ctype = self._read_request_param('ctype')

if not provider:
raise ConceptSchemeNotFoundException(scheme_id)
if 'atramhasis.force_display_label_language' in provider.metadata:
Expand All @@ -166,10 +169,10 @@ def concept_view(self):
else:
return Response('Thing without type: ' + str(c_id), status_int=500)
url = self.request.route_url('concept', scheme_id=scheme_id, c_id=c_id)
update_last_visited_concepts(self.request, {'label': c.label(self.request.locale_name).label, 'url': url})
update_last_visited_concepts(self.request, {'label': c.label(locale).label, 'url': url})
return {'concept': c, 'conceptType': concept_type, 'scheme_id': scheme_id,
'conceptschemes': conceptschemes, 'provider': provider,
'locale': locale}
'locale': locale, 'ctype': ctype, 'label': label}
except NoResultFound:
raise ConceptNotFoundException(c_id)

Expand All @@ -190,13 +193,17 @@ def search_result(self):
ctype = self._read_request_param('ctype')
provider = self.skos_registry.get_provider(scheme_id)
if provider:
if 'atramhasis.force_display_label_language' in provider.metadata:
locale = provider.metadata['atramhasis.force_display_label_language']
else:
locale = self.request.locale_name
if label is not None:
concepts = provider.find({'label': label, 'type': ctype}, language=self.request.locale_name, sort='label')
concepts = provider.find({'label': label, 'type': ctype}, language=locale, sort='label')
elif (label is None) and (ctype is not None):
concepts = provider.find({'type': ctype}, language=self.request.locale_name, sort='label')
concepts = provider.find({'type': ctype}, language=locale, sort='label')
else:
concepts = provider.get_all(language=self.request.locale_name, sort='label')
return {'concepts': concepts, 'scheme_id': scheme_id, 'conceptschemes': conceptschemes}
concepts = provider.get_all(language=locale, sort='label')
return {'concepts': concepts, 'scheme_id': scheme_id, 'conceptschemes': conceptschemes, 'ctype': ctype, 'label': label}
return Response(content_type='text/plain', status_int=404)

@view_config(route_name='locale')
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -7,8 +7,8 @@ skosprovider==0.7.1
#-e git+https://github.com/koenedaele/skosprovider.git@develop#egg=skosprovider
skosprovider_sqlalchemy==0.6.0
#-e git+https://github.com/koenedaele/skosprovider_sqlalchemy.git@0.6.0#egg=skosprovider_sqlalchemy
pyramid_skosprovider==0.9.0
#-e git+https://github.com/koenedaele/pyramid_skosprovider.git@0.9.0#egg=pyramid_skosprovider
pyramid_skosprovider==0.9.1
#-e git+https://github.com/koenedaele/pyramid_skosprovider.git@0.9.1#egg=pyramid_skosprovider
skosprovider_rdf==0.8.1
#-e git+https://github.com/OnroerendErfgoed/skosprovider_rdf.git@develop#egg=skosprovider_rdf
skosprovider_getty==0.5.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -113,7 +113,7 @@ def run(self):
]

setup(name='atramhasis',
version='0.7.0b1',
version='0.7.0b4',
description='A web based editor for thesauri adhering to the SKOS specification.',
long_description=README + '\n\n' + CHANGES,
long_description_content_type='text/x-rst',
Expand Down
20 changes: 20 additions & 0 deletions tests/test_functional.py
Expand Up @@ -723,6 +723,26 @@ def test_rdf_conceptscheme_turtle_ext(self):
self.assertEqual('200 OK', ttl_response.status)
self.assertEqual('text/turtle', ttl_response.content_type)

def test_rdf_conceptscheme_jsonld(self):
res = self.testapp.get('/conceptschemes/MATERIALS', headers={'Accept': 'application/ld+json'})
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

def test_rdf_conceptscheme_jsonld_ext(self):
res = self.testapp.get('/conceptschemes/MATERIALS.jsonld')
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

def test_rdf_individual_jsonld(self):
res = self.testapp.get('/conceptschemes/MATERIALS/c/1', headers={'Accept': 'application/ld+json'})
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

def test_rdf_individual_jsonld_ext(self):
res = self.testapp.get('/conceptschemes/MATERIALS/c/1.jsonld')
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

def test_rdf_individual_xml(self):
rdf_response = self.testapp.get('/conceptschemes/MATERIALS/c/1', headers={'Accept': 'application/rdf+xml'})
self.assertEqual('200 OK', rdf_response.status)
Expand Down

0 comments on commit e840ed2

Please sign in to comment.