def get(self, request, conceptid=None): if user_can_read_concepts(user=request.user): include_subconcepts = request.GET.get('includesubconcepts', 'true') == 'true' include_parentconcepts = request.GET.get('includeparentconcepts', 'true') == 'true' include_relatedconcepts = request.GET.get('includerelatedconcepts', 'true') == 'true' depth_limit = request.GET.get('depthlimit', None) lang = request.GET.get('lang', settings.LANGUAGE_CODE) try: indent = int(request.GET.get('indent', None)) except: indent = None if conceptid: try: ret = [] concept_graph = Concept().get(id=conceptid, include_subconcepts=include_subconcepts, include_parentconcepts=include_parentconcepts, include_relatedconcepts=include_relatedconcepts, depth_limit=depth_limit, up_depth_limit=None, lang=lang) ret.append(concept_graph) except models.Concept.DoesNotExist: return JSONResponse(status=404) except: return JSONResponse(status=500) else: return JSONResponse(status=500) else: return JSONResponse(status=500) return JSONResponse(ret, indent=indent)
def get(self, request, conceptid=None): if user_can_read_concepts(user=request.user): allowed_formats = ['json', 'json-ld'] format = request.GET.get('format', 'json-ld') if format not in allowed_formats: return JSONResponse(status=406, reason='incorrect format specified, only %s formats allowed' % allowed_formats) include_subconcepts = request.GET.get('includesubconcepts', 'true') == 'true' include_parentconcepts = request.GET.get('includeparentconcepts', 'true') == 'true' include_relatedconcepts = request.GET.get('includerelatedconcepts', 'true') == 'true' depth_limit = request.GET.get('depthlimit', None) lang = request.GET.get('lang', settings.LANGUAGE_CODE) try: indent = int(request.GET.get('indent', None)) except Exception: indent = None if conceptid: try: ret = [] concept_graph = Concept().get(id=conceptid, include_subconcepts=include_subconcepts, include_parentconcepts=include_parentconcepts, include_relatedconcepts=include_relatedconcepts, depth_limit=depth_limit, up_depth_limit=None, lang=lang) ret.append(concept_graph) except models.Concept.DoesNotExist: return JSONResponse(status=404) except Exception as e: return JSONResponse(status=500, reason=e) else: return JSONResponse(status=500) else: return JSONResponse(status=500) if format == 'json-ld': try: skos = SKOSWriter() value = skos.write(ret, format="nt") js = from_rdf(str(value), options={format: 'application/nquads'}) context = [{ "@context": { "skos": SKOS, "dcterms": DCTERMS, "rdf": str(RDF) } }, { "@context": settings.RDM_JSONLD_CONTEXT }] ret = compact(js, context) except Exception as e: return JSONResponse(status=500, reason=e) return JSONResponse(ret, indent=indent)