def items_json(request, identifier): # testing for using the new Open Context OCitem generator # that better integrates caching if request.GET.get('response') == 'solr': sd_obj = SolrDocument(identifier) sd_obj.solr_doc_prefix = request.GET.get('rel-prefix', '') sd_obj.make_solr_doc() json_output = json.dumps(sd_obj.fields, indent=4, ensure_ascii=False) return HttpResponse(json_output, content_type='application/json; charset=utf8') return items_graph(request, identifier, return_media='application/ld+json')
def html_view(request, uuid): request = RequestNegotiation().anonymize_request(request) # Handle some content negotiation for the item. req_neg = RequestNegotiation('text/html') req_neg.supported_types = [] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if not req_neg.supported: # The client may be wanting a non-HTML representation, so # use the following function to get it. return items_graph(request, uuid, item_type=ITEM_TYPE) # Proceed with constructing the HTML item ocitem = OCitem() if 'hashes' in request.GET: ocitem.assertion_hashes = True ocitem.get_item(uuid, True) if not ocitem.manifest: # Did not find a record for the table, check for redirects r_url = RedirectURL() r_ok = r_url.get_direct_by_type_id(ITEM_TYPE, uuid) if r_ok: # found a redirect!! return redirect(r_url.redirect, permanent=r_url.permanent) # raise Http404 raise Http404 # Construnct item the JSON-LD request.uuid = ocitem.manifest.uuid request.project_uuid = ocitem.manifest.project_uuid request.item_type = ocitem.manifest.item_type ts = TypeSupplement(ocitem.json_ld) ocitem.json_ld = ts.get_arachne_comparanda() rp = RootPath() base_url = rp.get_baseurl() temp_item = TemplateItem(request) temp_item.read_jsonld_dict(ocitem.json_ld) if not temp_item.view_permitted: # The client is not allowed to see this. template = loader.get_template('items/view401.html') context = { 'item': temp_item, 'base_url': base_url, 'user': request.user } return HttpResponse(template.render(context, request), status=401) # Now add templated item to the a response object template = loader.get_template('types/view.html') context = { 'item': temp_item, 'base_url': base_url, 'user': request.user } response = HttpResponse(template.render(context, request)) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response
def html_view(request, uuid, full_view=False): request = RequestNegotiation().anonymize_request(request) # Handle some content negotiation for the item. req_neg = RequestNegotiation('text/html') req_neg.supported_types = [] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if not req_neg.supported: # The client may be wanting a non-HTML representation, so # use the following function to get it. return items_graph(request, uuid, item_type=ITEM_TYPE) # Construnct the item ocitem = OCitem() ocitem.get_item(uuid) if not ocitem.manifest: # Did not find a record for the table, check for redirects r_url = RedirectURL() r_ok = r_url.get_direct_by_type_id(ITEM_TYPE, uuid) if r_ok: # found a redirect!! return redirect(r_url.redirect, permanent=r_url.permanent) # raise Http404 raise Http404 request.uuid = ocitem.manifest.uuid request.project_uuid = ocitem.manifest.project_uuid request.item_type = ocitem.manifest.item_type rp = RootPath() base_url = rp.get_baseurl() temp_item = TemplateItem(request) temp_item.read_jsonld_dict(ocitem.json_ld) if full_view: template = loader.get_template('media/full.html') else: template = loader.get_template('media/view.html') if not temp_item.view_permitted: # The client is not allowed to see this. template = loader.get_template('items/view401.html') context = { 'item': temp_item, 'base_url': base_url, 'user': request.user } return HttpResponse(template.render(context, request), status=401) # Now add templated item to the a response object context = { 'item': temp_item, 'fullview': full_view, 'base_url': base_url, 'user': request.user } response = HttpResponse(template.render(context, request)) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response
def html_view(request, uuid): request = RequestNegotiation().anonymize_request(request) # Handle some content negotiation for the item. req_neg = RequestNegotiation('text/html') req_neg.supported_types = [] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if not req_neg.supported: # The client may be wanting a non-HTML representation, so # use the following function to get it. return items_graph(request, uuid, item_type=ITEM_TYPE) ocitem = OCitem() ocitem.get_item(uuid) if not ocitem.manifest: # Did not find a record for the table, check for redirects r_url = RedirectURL() r_ok = r_url.get_direct_by_type_id(ITEM_TYPE, uuid) if r_ok: # found a redirect!! return redirect(r_url.redirect, permanent=r_url.permanent) # raise Http404 raise Http404 # check to see if there's related data via API calls. Add if so. request.uuid = ocitem.manifest.uuid request.project_uuid = ocitem.manifest.project_uuid request.item_type = ocitem.manifest.item_type subj_s = SubjectSupplement(ocitem.json_ld) ocitem.json_ld = subj_s.get_catal_related() rp = RootPath() base_url = rp.get_baseurl() temp_item = TemplateItem(request) temp_item.read_jsonld_dict(ocitem.json_ld) template = loader.get_template('subjects/view.html') if not temp_item.view_permitted: # The client is not allowed to see this. template = loader.get_template('items/view401.html') context = { 'item': temp_item, 'base_url': base_url, 'user': request.user } return HttpResponse(template.render(context, request), status=401) # The client is allowd to see the current item. context = {'item': temp_item, 'base_url': base_url, 'user': request.user} response = HttpResponse(template.render(context, request)) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response
def html_view(request, uuid): request = RequestNegotiation().anonymize_request(request) # Handle some content negotiation for the item. req_neg = RequestNegotiation('text/html') req_neg.supported_types = [] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if not req_neg.supported: # The client may be wanting a non-HTML representation, so # use the following function to get it. return items_graph(request, uuid, item_type=ITEM_TYPE) if request.GET.get('new') is not None: return html_view_new(request, uuid) ocitem = OCitem() ocitem.get_item(uuid, True) if not ocitem.manifest: # Did not find a record for the table, check for redirects r_url = RedirectURL() r_ok = r_url.get_direct_by_type_id(ITEM_TYPE, uuid) if r_ok: # found a redirect!! return redirect(r_url.redirect, permanent=r_url.permanent) # raise Http404 raise Http404 # Construnct item the JSON-LD request.uuid = ocitem.manifest.uuid request.project_uuid = ocitem.manifest.project_uuid request.item_type = ocitem.manifest.item_type rp = RootPath() base_url = rp.get_baseurl() proj_content = ProjectContent(ocitem.manifest.uuid, ocitem.manifest.slug, ocitem.json_ld) temp_item = TemplateItem() temp_item.proj_content = proj_content.get_project_content() temp_item.read_jsonld_dict(ocitem.json_ld) template = loader.get_template('projects/view.html') context = {'item': temp_item, 'base_url': base_url, 'user': request.user} response = HttpResponse(template.render(context, request)) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response
def html_view_new(request, uuid): request = RequestNegotiation().anonymize_request(request) # Handle some content negotiation for the item. req_neg = RequestNegotiation('text/html') req_neg.supported_types = [] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if not req_neg.supported: # The client may be wanting a non-HTML representation, so # use the following function to get it. return items_graph(request, uuid, item_type=ITEM_TYPE) # Proceed with constructing the HTML item ocitem = OCitemNew() if 'hashes' in request.GET: ocitem.assertion_hashes = True exists = ocitem.check_exists(uuid) if not exists: # Did not find a record for the table, check for redirects r_url = RedirectURL() r_ok = r_url.get_direct_by_type_id(ITEM_TYPE, uuid) if r_ok: # found a redirect!! return redirect(r_url.redirect, permanent=r_url.permanent) # raise Http404 raise Http404 # Construnct item the JSON-LD ocitem.generate_json_ld() rp = RootPath() base_url = rp.get_baseurl() proj_content = ProjectContent(ocitem.manifest.uuid, ocitem.manifest.slug, ocitem.json_ld) html_temp = HTMLtemplate() html_temp.proj_context_json_ld = ocitem.proj_context_json_ld html_temp.proj_content = proj_content.get_project_content() html_temp.read_jsonld_dict(ocitem.json_ld) template = loader.get_template('projects/view.html') context = {'item': html_temp, 'base_url': base_url, 'user': request.user} response = HttpResponse(template.render(context, request)) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response
def turtle_view(request, uuid): """Returns a Turtle media response for an item""" return items_graph( request, uuid, return_media='text/turtle', item_type=ITEM_TYPE)
def rdf_view(request, uuid): """Returns a RDF/XML media response for an item""" return items_graph( request, uuid, return_media='application/rdf+xml', item_type=ITEM_TYPE)
def geojson_view(request, uuid): """Returns a GeoJSON media response for an item""" return items_graph(request, uuid, return_media='application/vnd.geo+json', item_type=ITEM_TYPE)
def rdf_view(request, uuid): """Returns a RDF/XML media response for an item""" return items_graph( request, uuid, return_media='application/rdf+xml', item_type=ITEM_TYPE)
def ntrpls_view(request, uuid): """Returns a N-Triples media response for an item""" return items_graph( request, uuid, return_media='application/n-triples', item_type=ITEM_TYPE)
def jsonld_view(request, uuid): """Returns a JSON-LD media response for an item""" return items_graph( request, uuid, return_media='application/ld+json', item_type=ITEM_TYPE)
def turtle_view(request, uuid): """Returns a Turtle media response for an item""" return items_graph( request, uuid, return_media='text/turtle', item_type=ITEM_TYPE)
def geojson_view(request, uuid): """Returns a GeoJSON media response for an item""" return items_graph( request, uuid, return_media='application/vnd.geo+json', item_type=ITEM_TYPE)
def jsonld_view(request, uuid): """Returns a JSON-LD media response for an item""" return items_graph( request, uuid, return_media='application/ld+json', item_type=ITEM_TYPE)
def nquads_view(request, uuid): """Returns a N-Quads media response for an item""" return items_graph( request, uuid, return_media='application/n-quads', item_type=ITEM_TYPE)
def nquads_view(request, uuid): """Returns a N-Quads media response for an item""" return items_graph( request, uuid, return_media='application/n-quads', item_type=ITEM_TYPE)
def items_json(request, identifier): # testing for using the new Open Context OCitem generator # that better integrates caching return items_graph(request, identifier, return_media='application/ld+json')
def ntrpls_view(request, uuid): """Returns a N-Triples media response for an item""" return items_graph( request, uuid, return_media='application/n-triples', item_type=ITEM_TYPE)