本文整理汇总了Python中opencontext_py.libs.requestnegotiation.RequestNegotiation类的典型用法代码示例。如果您正苦于以下问题:Python RequestNegotiation类的具体用法?Python RequestNegotiation怎么用?Python RequestNegotiation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestNegotiation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index_atom
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
示例2: json_view
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
示例3: sponsors_view
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)
示例4: terms_view
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)
示例5: bibliography_view
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)
示例6: ip_view
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)
示例7: services_view
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)
示例8: recipes_view
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)
示例9: estimate_view
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)
示例10: index_view
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)
示例11: json_view
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)
示例12: pub_view
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)
示例13: html_view
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
示例14: index
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)
示例15: projects_json
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