Skip to content

Commit

Permalink
#625 add JSON/LD download links
Browse files Browse the repository at this point in the history
  • Loading branch information
Emrys committed Oct 21, 2020
1 parent 2b30990 commit 325dc55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions atramhasis/audit.py
Expand Up @@ -24,6 +24,7 @@ def _origin_from_request(request):

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
1 change: 1 addition & 0 deletions atramhasis/templates/concept.jinja2
Expand Up @@ -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
23 changes: 16 additions & 7 deletions atramhasis/views/rdf.py
@@ -1,7 +1,8 @@
# -*- 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
Expand Down Expand Up @@ -122,13 +123,21 @@ def rdf_individual_export_turtle(self):
return response

@audit
@view_config(route_name='atramhasis.rdf_conceptscheme_jsonld', permission='view', renderer='skosjsonld')
@view_config(route_name='atramhasis.rdf_conceptscheme_jsonld_ext', permission='view', renderer='skosjsonld')
@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):
return ProviderView(self.request).get_conceptscheme_jsonld()
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', renderer='skosjsonld')
@view_config(route_name='atramhasis.rdf_individual_jsonld_ext', permission='view', renderer='skosjsonld')
@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):
return ProviderView(self.request).get_concept()
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

0 comments on commit 325dc55

Please sign in to comment.