def sponsors_view(request): """ Get the page about sponsors """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/sponsors', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Sources of financial support for '\ 'Open Context and collaborative institutions providing '\ 'complementary services', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/sponsors.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Intellectual Property', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def index(request): """ Get the search context JSON-LD """ rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') old_view = False template = loader.get_template('index/view.html') if 'test' in request.GET: template = loader.get_template('index/view-initial-minimal.html') old_view = True context = RequestContext( request, { 'base_url': base_url, 'old_view': old_view, 'page_title': 'Open Context: Publisher of Research Data', 'act_nav': 'home', 'nav_items': settings.NAV_ITEMS }) if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(template.render(context), status=415)
def index_atom(request): """ Get the search context JSON-LD """ mf = ManifestFeed() xml_string = mf.make_feed(request.GET) if xml_string is not False: req_neg = RequestNegotiation('application/atom+xml') req_neg.supported_types = ['application/atom+xml'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if 'atom' in req_neg.use_response_type: # content negotiation requested Atom return HttpResponse(xml_string, content_type=req_neg.use_response_type + "; charset=utf8") else: # give atom anyway return HttpResponse(xml_string, content_type='application/atom+xml' + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type='text/html' + "; charset=utf8", status=415) else: # no feed of this page or type raise Http404
def json_view(request, uuid): ocitem = OCitem() if 'hashes' in request.GET: ocitem.assertion_hashes = True ocitem.get_item(uuid, True) if(ocitem.manifest is not False): req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json', 'application/vnd.geo+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: json_output = json.dumps(ocitem.json_ld, indent=4, ensure_ascii=False) if 'callback' in request.GET: funct = request.GET['callback'] return HttpResponse(funct + '(' + json_output + ');', content_type='application/javascript' + "; charset=utf8") else: return HttpResponse(json_output, content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: raise Http404
def terms_view(request): """ Get the page about Terms """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/terms', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Terms and Conditions of Use, and '\ 'Privacy Policies for Open Context', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/terms.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Terms of Use and Privacy Policies', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def pub_view(request): """ Get publishing overview page """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/publishing', 'site_name': settings.CANONICAL_SITENAME, 'description': 'How to publish archaeological research data '\ 'with Open Context', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/publishing.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Publishing', 'act_nav': 'about', 'og': open_graph, 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def json_view(request, uuid): ocitem = OCitem() if 'hashes' in request.GET: ocitem.assertion_hashes = True ocitem.get_item(uuid, True) if (ocitem.manifest is not False): req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: json_output = json.dumps(ocitem.json_ld, indent=4, ensure_ascii=False) return HttpResponse(json_output, content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: raise Http404
def gazetteer(request): """ Returns RDF void data describing different datasets for Pelagious """ p_gg = PelagiosGazetteerGraph() p_gg.request = request if 'refresh' in request.GET: # we're going to refresh the cache p_gg.refresh_cache = True p_gg.make_graph() req_neg = RequestNegotiation('text/turtle') req_neg.supported_types = ['application/rdf+xml', 'text/n3', 'application/n-triples'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: content_type = req_neg.use_response_type + '; charset=utf8' output = p_gg.g.serialize(format=req_neg.use_response_type) return HttpResponse(output, content_type=content_type) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type="text/plain; charset=utf8", status=415) else: # default to outputting in turtle output = p_gg.g.serialize(format='turtle') return HttpResponse(output, content_type='text/turtle; charset=utf8')
def projects_json(request, uuid): """ provides a JSON-LD context for the data in a project. This will include annotations of predicates and types """ proj_context = ProjectContext(uuid, request) if 'hashes' in request.GET: proj_context.assertion_hashes = True if proj_context.manifest is not False: req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json', 'application/vnd.geo+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: json_ld = proj_context.make_context_json_ld() json_output = json.dumps(json_ld, indent=4, ensure_ascii=False) if 'callback' in request.GET: funct = request.GET['callback'] return HttpResponse(funct + '(' + json_output + ');', content_type='application/javascript' + "; charset=utf8") else: return HttpResponse(json_output, content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: raise Http404
def html_view(request, uuid): ocitem = OCitem() ocitem.get_item(uuid) if ocitem.manifest is not False: rp = RootPath() base_url = rp.get_baseurl() temp_item = TemplateItem(request) temp_item.read_jsonld_dict(ocitem.json_ld) template = loader.get_template("media/view.html") if temp_item.view_permitted: req_neg = RequestNegotiation("text/html") req_neg.supported_types = ["application/json", "application/ld+json"] if "HTTP_ACCEPT" in request.META: req_neg.check_request_support(request.META["HTTP_ACCEPT"]) if req_neg.supported: if "json" in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD return HttpResponse( json.dumps(ocitem.json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8", ) else: context = RequestContext(request, {"item": temp_item, "fullview": False, "base_url": base_url}) return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse( req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415 ) else: template = loader.get_template("items/view401.html") context = RequestContext(request, {"item": temp_item, "base_url": base_url}) return HttpResponse(template.render(context), status=401) else: raise Http404
def bibliography_view(request): """ Get page about bibliography / publications """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/bibliography', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Publications related to Open Context and its '\ 'contributions to research data management, '\ 'archaeological ethics, scholarly communications, and '\ 'professional practice', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/bibliography.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Bibliography', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def ip_view(request): """ Get page about IP policies """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/intellectual-property', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Intellectual property policies for Open Context and '\ 'ethical guidance for contributors and users of '\ 'archaeological research data', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/intellectual-property.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Intellectual Property', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def services_view(request): """ Get page documenting the API """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/technology', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Overview of the APIs (machine-readable data) '\ 'offered by Open Context to promote '\ 'interoperability and new uses of data', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/services.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Web Services and APIs', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def recipes_view(request): """ Get page about recipes using the API """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/recipes', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Specific guidance on the use of Open Context APIs '\ '(machine-readable data) to meet certain data '\ 'management needs', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/recipes.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - API Cookbook', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def estimate_view(request): """ Get page with publication project cost estimation """ rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/estimate', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Estimate data publication and archiving '\ 'costs with Open Context to help budget for '\ 'grant data management plans', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/estimate.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Cost Estimate', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def index_view(request): """ Get the search context JSON-LD """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Video and introduction to Open Context, an open-access ' 'data publication service for archaeology ', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': 'https://opencontext.wistia.com/medias/s0g0fsyqkz' } template = loader.get_template('about/index.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About', 'act_nav': 'about', 'og': open_graph, 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def json_view(request, spatial_context=None): """ API for searching Open Context """ rd = RequestDict() request_dict_json = rd.make_request_dict_json(request, spatial_context) solr_s = SolrSearch() if solr_s.solr is not False: response = solr_s.search_solr(request_dict_json) m_json_ld = MakeJsonLd(request_dict_json) # share entities already looked up. Saves database queries m_json_ld.entities = solr_s.entities m_json_ld.request_full_path = request.get_full_path() m_json_ld.spatial_context = spatial_context json_ld = m_json_ld.convert_solr_json(response.raw_content) req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] recon_obj = Reconciliation() json_ld = recon_obj.process(request.GET, json_ld) if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support return HttpResponse(json.dumps(json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415) else: template = loader.get_template('500.html') context = RequestContext(request, {'error': 'Solr Connection Problem'}) return HttpResponse(template.render(context), status=503)
def index(request): """ Get home page """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') old_view = False open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url, 'site_name': settings.CANONICAL_SITENAME, 'description': 'Home page for Open Context, an open access service for publishing, '\ 'preserving, exploring and analyzing archaeological '\ 'research data', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('index/view.html') context = { 'base_url': base_url, 'old_view': old_view, 'page_title': 'Open Context: Publisher of Research Data', 'og': open_graph, 'act_nav': 'home', 'nav_items': settings.NAV_ITEMS } if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(template.render(context, request), status=415)
def html_view(request, uuid): ocitem = OCitem() ocitem.get_item(uuid, True) if(ocitem.manifest is not False): rp = RootPath() base_url = rp.get_baseurl() temp_item = TemplateItem() temp_item.read_jsonld_dict(ocitem.json_ld) template = loader.get_template('projects/view.html') req_neg = RequestNegotiation('text/html') req_neg.supported_types = ['application/json', 'application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if 'json' in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD return HttpResponse(json.dumps(ocitem.json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: context = RequestContext(request, {'item': temp_item, 'base_url': base_url}) return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: raise Http404
def query_json(request, spatial_context=None): """ API for searching Open Context """ request_dict = utilities.make_request_obj_dict( request, spatial_context=spatial_context) response_dict = process_solr_query(request_dict) req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) # Associate the request media type with the request so we can # make sure that different representations of this resource get different # cache responses. request.content_type = req_neg.use_response_type if not req_neg.supported: # Client wanted a mimetype we don't support response = HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response return make_json_response(request, req_neg, response_dict)
def html_view(request, uuid): ocitem = OCitem() ocitem.get_item(uuid, True) if (ocitem.manifest is not False): rp = RootPath() base_url = rp.get_baseurl() temp_item = TemplateItem() temp_item.read_jsonld_dict(ocitem.json_ld) template = loader.get_template('projects/view.html') req_neg = RequestNegotiation('text/html') req_neg.supported_types = ['application/json', 'application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if 'json' in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD return HttpResponse(json.dumps(ocitem.json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: context = RequestContext(request, { 'item': temp_item, 'base_url': base_url }) return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: raise Http404
def index(request): """ Get the search context JSON-LD """ rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation("text/html") old_view = False template = loader.get_template("index/view.html") if "test" in request.GET: template = loader.get_template("index/view-initial-minimal.html") old_view = True context = RequestContext( request, { "base_url": base_url, "old_view": old_view, "page_title": "Open Context: Publisher of Research Data", "act_nav": "home", "nav_items": settings.NAV_ITEMS, }, ) if "HTTP_ACCEPT" in request.META: req_neg.check_request_support(request.META["HTTP_ACCEPT"]) if req_neg.supported: # requester wanted a mimetype we DO support return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(template.render(context), status=415)
def gazetteer(request): """ Returns RDF void data describing different datasets for Pelagious """ p_gg = PelagiosGazetteerGraph() p_gg.request = request if 'refresh' in request.GET: # we're going to refresh the cache p_gg.refresh_cache = True p_gg.make_graph() req_neg = RequestNegotiation('text/turtle') req_neg.supported_types = [ 'application/rdf+xml', 'text/n3', 'application/n-triples' ] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: content_type = req_neg.use_response_type + '; charset=utf8' output = p_gg.g.serialize(format=req_neg.use_response_type) return HttpResponse(output, content_type=content_type) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type="text/plain; charset=utf8", status=415) else: # default to outputting in turtle output = p_gg.g.serialize(format='turtle') return HttpResponse(output, content_type='text/turtle; charset=utf8')
def html_view(request, spatial_context=None): rp = RootPath() base_url = rp.get_baseurl() rd = RequestDict() request_dict_json = rd.make_request_dict_json(request, spatial_context) url = request.get_full_path() if 'http://' not in url \ and 'https://' not in url: url = base_url + url if '?' in url: json_url = url.replace('?', '.json?') else: json_url = url + '.json' solr_s = SolrSearch() if solr_s.solr is not False: response = solr_s.search_solr(request_dict_json) m_json_ld = MakeJsonLd(request_dict_json) # share entities already looked up. Saves database queries m_json_ld.entities = solr_s.entities m_json_ld.request_full_path = request.get_full_path() m_json_ld.spatial_context = spatial_context json_ld = m_json_ld.convert_solr_json(response.raw_content) req_neg = RequestNegotiation('text/html') req_neg.supported_types = ['application/json', 'application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if 'json' in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD recon_obj = Reconciliation() json_ld = recon_obj.process(request.GET, json_ld) return HttpResponse(json.dumps(json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: # now make the JSON-LD into an object suitable for HTML templating st = SearchTemplate(json_ld) st.process_json_ld() template = loader.get_template('sets/view.html') context = RequestContext(request, {'st': st, 'url': url, 'json_url': json_url, 'base_url': base_url}) if req_neg.supported: return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: template = loader.get_template('500.html') context = RequestContext(request, {'error': 'Solr Connection Problem'}) return HttpResponse(template.render(context), status=503)
def project_vocabs(request, uuid, return_media=None): """ Provides a RDF serialization, defaulting to a JSON-LD context for the data in a project. This will include a graph object that has annotations annotations of predicates and types """ proj_context = ProjectContext(uuid, request) if 'hashes' in request.GET: proj_context.assertion_hashes = True if not proj_context.manifest: raise Http404 req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] req_neg.supported_types += RDF_SERIALIZATIONS if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if return_media: req_neg.check_request_support(return_media) req_neg.use_response_type = return_media # Associate the request media type with the request so we can # make sure that different representations of this resource get different # cache responses. request.content_type = req_neg.use_response_type if not req_neg.supported: # client wanted a mimetype we don't support response = HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response json_ld = proj_context.make_context_and_vocab_json_ld() # Check first if the output is requested to be an RDF format graph_output = graph_serialize(req_neg.use_response_type, json_ld) if graph_output: # Return with some sort of graph output response = HttpResponse(graph_output, content_type=req_neg.use_response_type + "; charset=utf8") patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response # We're outputing JSON json_output = json.dumps(json_ld, indent=4, ensure_ascii=False) if 'callback' in request.GET: funct = request.GET['callback'] response = HttpResponse(funct + '(' + json_output + ');', content_type='application/javascript' + "; charset=utf8") patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response else: response = HttpResponse(json_output, content_type=req_neg.use_response_type + "; charset=utf8") patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response
def html_view(request, identifier): rp = RootPath() base_url = rp.get_baseurl() uri = 'http://opencontext.org/vocabularies/' + str(identifier) lequiv = LinkEquivalence() id_list = lequiv.get_identifier_list_variants(uri) lequiv = LinkEquivalence() id_s_list = lequiv.get_identifier_list_variants(uri + '/') for id_s in id_s_list: if id_s not in id_list: # add the slashed version to the list id_list.append(id_s) entity = False for test_id in id_list: ent = Entity() found = ent.dereference(test_id) if found is False: found = ent.dereference(test_id, test_id) if found: entity = ent break if entity is not False: t_vocab = TemplateVocab() t_vocab.create_template_for_entity(entity) t_vocab.make_json_for_html() req_neg = RequestNegotiation('text/html') req_neg.supported_types = ['application/ld+json', 'application/json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if 'json' in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD json_obj = t_vocab.make_json_obj() return HttpResponse(json.dumps(json_obj, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: template = loader.get_template('vocabularies/view.html') context = { 'item': t_vocab, 'base_url': base_url, 'page_title': 'Open Context: Vocabularies + Ontologies', 'act_nav': 'vocabularies', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type="text/plain; charset=utf8", status=415) else: raise Http404
def project_annotations(request, identifier): """ Returns RDF open annotation assertions conforming to Pelagios specifications that link Open Context resources with place entities in gazetteers """ ent = Entity() found = ent.dereference(identifier) if found or identifier == 'web': if ent.item_type == 'projects' or identifier == 'web': pelagios = PelagiosGraph() pelagios.test_limit = None if 'refresh' in request.GET: # we're going to refresh the cache pelagios.refresh_cache = True if identifier != 'web': pp = ProjectPermissions(ent.uuid) permitted = pp.view_allowed(request) pelagios.project_uuids = [ent.uuid] else: # we're doing web annotations pelagios.do_web_annotations = True permitted = True if permitted: pelagios.get_graph() req_neg = RequestNegotiation('text/turtle') req_neg.supported_types = [ 'application/rdf+xml', 'text/n3', 'application/n-triples' ] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: content_type = req_neg.use_response_type + '; charset=utf8' output = pelagios.g.serialize( format=req_neg.use_response_type) return HttpResponse(output, content_type=content_type) else: # client wanted a mimetype we don't support return HttpResponse( req_neg.error_message, content_type="text/plain; charset=utf8", status=415) else: # default to outputting in turtle output = pelagios.g.serialize(format='turtle') return HttpResponse( output, content_type='text/turtle; charset=utf8') else: return HttpResponse('Not authorized to get this resource', content_type='text/html; charset=utf8', status=401) else: found = False if found is False: raise Http404
def project_annotations(request, identifier): """ Returns RDF open annotation assertions conforming to Pelagios specifications that link Open Context resources with place entities in gazetteers """ ent = Entity() found = ent.dereference(identifier) if found or identifier == 'web': if ent.item_type == 'projects' or identifier == 'web': pelagios = PelagiosGraph() pelagios.test_limit = None if 'refresh' in request.GET: # we're going to refresh the cache pelagios.refresh_cache = True if identifier != 'web': pp = ProjectPermissions(ent.uuid) permitted = pp.view_allowed(request) pelagios.project_uuids = [ent.uuid] else: # we're doing web annotations pelagios.do_web_annotations = True permitted = True if permitted: pelagios.get_graph() req_neg = RequestNegotiation('text/turtle') req_neg.supported_types = ['application/rdf+xml', 'text/n3', 'application/n-triples'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: content_type = req_neg.use_response_type + '; charset=utf8' output = pelagios.g.serialize(format=req_neg.use_response_type) return HttpResponse(output, content_type=content_type) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type="text/plain; charset=utf8", status=415) else: # default to outputting in turtle output = pelagios.g.serialize(format='turtle') return HttpResponse(output, content_type='text/turtle; charset=utf8') else: return HttpResponse('Not authorized to get this resource', content_type='text/html; charset=utf8', status=401) else: found = False if found is False: raise Http404
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 index(request): """ Get the item context JSON-LD """ oai_obj = OAIpmh() req_neg = RequestNegotiation('application/xml') req_neg.supported_types = ['application/xml'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support xml = oai_obj.process_request(request) return HttpResponse(oai_obj.output_xml_string(), content_type=req_neg.use_response_type + "; charset=utf8", status=oai_obj.http_resp_code) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def html_view(request, uuid): ocitem = OCitem() ocitem.get_item(uuid) if (ocitem.manifest is not False): # check to see if there's related data via API calls. Add if so. 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 temp_item.view_permitted: req_neg = RequestNegotiation('text/html') req_neg.supported_types = [ 'application/json', 'application/ld+json' ] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if 'json' in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD return HttpResponse( json.dumps(ocitem.json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: context = RequestContext(request, { 'item': temp_item, 'base_url': base_url }) return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: template = loader.get_template('items/view401.html') context = RequestContext(request, {'item': temp_item}) return HttpResponse(template.render(context), status=401) else: raise Http404
def index_json(request): spatial_context=None rp = RootPath() base_url = rp.get_baseurl() rd = RequestDict() request_dict_json = rd.make_request_dict_json(request, spatial_context) url = request.get_full_path() if 'http://' not in url \ and 'https://' not in url: url = base_url + url if '?' in url: json_url = url.replace('?', '.json?') else: json_url = url + '.json' json_url = json_url.replace('/projects/.json', '') solr_s = SolrSearch() solr_s.do_context_paths = False solr_s.item_type_limit = 'projects' if solr_s.solr is not False: response = solr_s.search_solr(request_dict_json) m_json_ld = MakeJsonLd(request_dict_json) m_json_ld.base_search_link = '/projects/' # share entities already looked up. Saves database queries m_json_ld.entities = solr_s.entities m_json_ld.request_full_path = request.get_full_path() m_json_ld.spatial_context = spatial_context json_ld = m_json_ld.convert_solr_json(response.raw_content) req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support return HttpResponse(json.dumps(json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415) else: template = loader.get_template('500.html') context = RequestContext(request, {'error': 'Solr Connection Problem'}) return HttpResponse(template.render(context), status=503)
def search_view(request): """ Get the search context JSON-LD """ search_context_obj = SearchContext() json_ld = LastUpdatedOrderedDict() json_ld['@context'] = search_context_obj.context req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support return HttpResponse(json.dumps(json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def query_html(request, spatial_context=None): """HTML representation for searching Open Context """ request_dict = utilities.make_request_obj_dict( request, spatial_context=spatial_context) response_dict = process_solr_query(request_dict.copy()) req_neg = RequestNegotiation('text/html') req_neg.supported_types = [ 'application/json', 'application/ld+json', ] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) # Associate the request media type with the request so we can # make sure that different representations of this resource get different # cache responses. request.content_type = req_neg.use_response_type if not req_neg.supported: # Client wanted a mimetype we don't support response = HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response if req_neg.use_response_type.endswith('json'): return make_json_response(request, req_neg, response_dict) rp = RootPath() # Disable the search template and just use vue with the JSON # API. # search_temp = SearchTemplate(response_dict.copy()) context = { 'st': response_dict.copy(), 'base_url': rp.get_baseurl(), 'api_url': response_dict.get('id'), 'configs': configs, } template = loader.get_template('search_vue/view.html') response = HttpResponse(template.render(context, request)) patch_vary_headers(response, ['accept', 'Accept', 'content-type']) return response
def index_json(request): spatial_context = None rp = RootPath() base_url = rp.get_baseurl() rd = RequestDict() request_dict_json = rd.make_request_dict_json(request, spatial_context) url = request.get_full_path() if 'http://' not in url \ and 'https://' not in url: url = base_url + url if '?' in url: json_url = url.replace('?', '.json?') else: json_url = url + '.json' json_url = json_url.replace('/projects/.json', '') solr_s = SolrSearch() solr_s.do_context_paths = False solr_s.item_type_limit = 'projects' if solr_s.solr is not False: response = solr_s.search_solr(request_dict_json) m_json_ld = MakeJsonLd(request_dict_json) m_json_ld.base_search_link = '/projects/' # share entities already looked up. Saves database queries m_json_ld.entities = solr_s.entities m_json_ld.request_full_path = request.get_full_path() m_json_ld.spatial_context = spatial_context json_ld = m_json_ld.convert_solr_json(response.raw_content) req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support return HttpResponse(json.dumps(json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415) else: template = loader.get_template('500.html') context = RequestContext(request, {'error': 'Solr Connection Problem'}) return HttpResponse(template.render(context), status=503)
def json_view(request, uuid): ocitem = OCitem() ocitem.get_item(uuid) if ocitem.manifest is not False: req_neg = RequestNegotiation("application/json") req_neg.supported_types = ["application/ld+json"] if "HTTP_ACCEPT" in request.META: req_neg.check_request_support(request.META["HTTP_ACCEPT"]) if req_neg.supported: json_output = json.dumps(ocitem.json_ld, indent=4, ensure_ascii=False) return HttpResponse(json_output, content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse( req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415 ) else: raise Http404
def json_view(request, identifier): rp = RootPath() base_url = rp.get_baseurl() uri = 'http://opencontext.org/vocabularies/' + str(identifier) lequiv = LinkEquivalence() id_list = lequiv.get_identifier_list_variants(uri) lequiv = LinkEquivalence() id_s_list = lequiv.get_identifier_list_variants(uri + '/') for id_s in id_s_list: if id_s not in id_list: # add the slashed version to the list id_list.append(id_s) entity = False for test_id in id_list: ent = Entity() found = ent.dereference(test_id) if found is False: found = ent.dereference(test_id, test_id) if found: entity = ent break if entity is not False: t_vocab = TemplateVocab() t_vocab.create_template_for_entity(entity) json_obj = t_vocab.make_json_obj() req_neg = RequestNegotiation('application/ld+json') req_neg.supported_types = ['application/json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: return HttpResponse(json.dumps(json_obj, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type="text/plain; charset=utf8", status=415) else: raise Http404
def html_view(request, uuid): ocitem = OCitem() ocitem.get_item(uuid) if ocitem.manifest is not False: # check to see if there's related data via API calls. Add if so. 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 temp_item.view_permitted: req_neg = RequestNegotiation('text/html') req_neg.supported_types = ['application/json', 'application/ld+json', 'application/vnd.geo+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if 'json' in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD return HttpResponse(json.dumps(ocitem.json_ld, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: context = RequestContext(request, {'item': temp_item, 'base_url': base_url}) return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: template = loader.get_template('items/view401.html') context = RequestContext(request, {'item': temp_item}) return HttpResponse(template.render(context), status=401) else: raise Http404
def index_view(request): """ Get the search context JSON-LD """ rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support template = loader.get_template('vocabularies/index.html') context = { 'base_url': base_url, 'page_title': 'Open Context: Vocabularies + Ontologies', 'act_nav': 'vocabularies', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def people_view(request): """ Get the search context JSON-LD """ rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support template = loader.get_template('about/people.html') context = RequestContext(request, {'base_url': base_url, 'page_title': 'Open Context: About - People', 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS}) return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)
def csv_view(request, table_id): request = RequestNegotiation().anonymize_request(request) exp_tt = ExpTableTemplating(table_id) if exp_tt.exp_tab is not False: exp_tt.prep_csv() req_neg = RequestNegotiation('text/csv') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if isinstance(exp_tt.csv_url, str): return redirect(exp_tt.csv_url, permanent=False) else: dump = CSVdump() return dump.web_dump(exp_tt.table_id) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: raise Http404
def json_view(request, table_id): exp_tt = ExpTableTemplating(table_id) if exp_tt.exp_tab is not False: json_ld = exp_tt.make_json_ld() req_neg = RequestNegotiation('application/json') req_neg.supported_types = ['application/ld+json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: json_output = json.dumps(json_ld, indent=4, ensure_ascii=False) return HttpResponse(json_output, content_type=req_neg.use_response_type + "; charset=utf8") else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415) else: raise Http404
def concepts_view(request): """ Get concepts overview """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support template = loader.get_template('about/temp.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Concepts', 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415)