本文整理汇总了Python中pyramid.request.Request.resource_url方法的典型用法代码示例。如果您正苦于以下问题:Python Request.resource_url方法的具体用法?Python Request.resource_url怎么用?Python Request.resource_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.request.Request
的用法示例。
在下文中一共展示了Request.resource_url方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_breadcrumbs
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import resource_url [as 别名]
def get_breadcrumbs(context: Resource, request: Request, root_iface: type=None, current_view_name=None, current_view_url=None) -> typing.List:
"""Create breadcrumbs path data how to get to this resource from the root.
Traverse context :class:`Resource` up to the root resource in the reverse order. Fill in data for rendering
Bootstrap breacrumbs title. Each traversed resource must provide ``get_title()`` method giving a human readable title for the resource.
:param current_view_name: Optional user visible name of the current view for the bottom most resource.
:param current_view_url: Full URL to the current view
:param root_iface: If you want to traverse only subset of elements and stop a certain parent, optional root can be marked with an interface. If not given assume :class:`websauna.system.core.interfaces.IRoot`. Optionally traversing is terminated when reaching ``None`` as the ``__parent__` pointer.
:return: List of {url, name, resource} dictionaries
"""
elems = []
if not root_iface:
root_iface = IRoot
assert issubclass(root_iface, Interface), "Traversing root must be declared by an interface, got {}".format(root_iface)
# Looks like it is not possible to dig out the matched view from Pyramid request,
# so we need to explicitly pass it if we want it to appear in URL
if current_view_name:
assert current_view_url
elems.append(dict(url=current_view_url, name=current_view_name))
while context and not root_iface.providedBy(context):
if not hasattr(context, "get_title"):
raise RuntimeError("Breadcrumbs part missing get_title(): {}".format(context))
elems.append(dict(url=request.resource_url(context), name=get_human_readable_resource_name(context), resource=context))
if not hasattr(context, "__parent__"):
raise RuntimeError("Broken traverse lineage on {}, __parent__ missing".format(context))
if not isinstance(context, Resource):
raise RuntimeError("Lineage has item not compatible with breadcrums: {}".format(context))
context = context.__parent__
# Add the last (root) element
entry = dict(url=request.resource_url(context), name=get_human_readable_resource_name(context), resource=context)
elems.append(entry)
elems.reverse()
return elems
示例2: validate_post_root_versions
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import resource_url [as 别名]
def validate_post_root_versions(context, request: Request):
"""Check and transform the 'root_version' paths to resources."""
# TODO: make this a colander validator and move to schema.py
# use the catalog to find IItemversions
root_versions = request.validated.get("root_versions", [])
valid_root_versions = []
for root in root_versions:
if not IItemVersion.providedBy(root):
error = "This resource is not a valid " "root version: {}".format(request.resource_url(root))
request.errors.append(error_entry("body", "root_versions", error))
continue
valid_root_versions.append(root)
request.validated["root_versions"] = valid_root_versions
示例3: validate_post_root_versions
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import resource_url [as 别名]
def validate_post_root_versions(context, request: Request):
"""Check and transform the 'root_version' paths to resources."""
# TODO: make this a colander validator and move to schema.py
root_versions = request.validated.get('root_versions', [])
valid_root_versions = []
for root in root_versions:
if not IItemVersion.providedBy(root):
error = 'This resource is not a valid ' \
'root version: {}'.format(request.resource_url(root))
request.errors.append(error_entry('body', 'root_versions', error))
continue
valid_root_versions.append(root)
request.validated['root_versions'] = valid_root_versions