本文整理汇总了Python中opencontext_py.libs.requestnegotiation.RequestNegotiation.item_type方法的典型用法代码示例。如果您正苦于以下问题:Python RequestNegotiation.item_type方法的具体用法?Python RequestNegotiation.item_type怎么用?Python RequestNegotiation.item_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opencontext_py.libs.requestnegotiation.RequestNegotiation
的用法示例。
在下文中一共展示了RequestNegotiation.item_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: html_view
# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import item_type [as 别名]
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