cubicweb_web.views.urlpublishing
#
Associate urlâs path to view identifier / rql queries.
CubicWeb finds all registered URLPathEvaluators, orders them according
to their priority
attribute and calls their evaluate_path()
method. The first that returns something and doesnât raise a
PathDontMatch
exception wins.
Here is the default evaluator chain:
cubicweb_web.views.urlpublishing.RawPathEvaluator
handles unique url segments that match exactly one of the registered controllerâs __regid__. Urls such as /view?, /edit?, /json? fall in that category;cubicweb_web.views.urlpublishing.EidPathEvaluator
handles unique url segments that are eids (e.g. /1234);cubicweb_web.views.urlpublishing.URLRewriteEvaluator
selects all urlrewriter components, sorts them according to their priority, call theirrewrite()
method, the first one that doesnât raise aKeyError
wins. This is where thecubicweb_web.views.urlrewrite
andcubicweb_web.views.urlrewrite.SimpleReqRewriter
comes into play;cubicweb_web.views.urlpublishing.RestPathEvaluator
handles urls based on entity types and attributes : <etype>((/<attribute name>])?/<attribute value>)? This is whycwuser/carlos
works;cubicweb_web.views.urlpublishing.ActionPathEvaluator
handles any of the previous paths with an additional trailing â/<action>â segment, <action> being one of the registered actionsâ __regid__.
Note
Actionpath executes a query whose results is lost because of redirecting instead of direct traversal.
- exception cubicweb_web.views.urlpublishing.PathDontMatch[source]#
exception used by url evaluators to notify they canât evaluate a path
- class cubicweb_web.views.urlpublishing.URLPublisherComponent(vreg, default_method='view')[source]#
Bases:
cubicweb_web.view.Component
Associate url path to view identifier / rql queries, by applying a chain of urlpathevaluator components.
An evaluator is a URLPathEvaluator subclass with an .evaluate_path method taking the request object and the path to publish as argument. It will either return a publishing method identifier and an rql query on success or raise a PathDontMatch exception on failure. URL evaluators are called according to their priority attribute, with 0 as the greatest priority and greater values as lower priority. The first evaluator returning a result or raising something else than PathDontMatch will stop the handlers chain.
- process(req, path)[source]#
Given a URL (essentially characterized by a path on the server, but additional information may be found in the request object), return a publishing method identifier (e.g. controller) and an optional result set.
- Parameters
req (cubicweb_web.request.CubicWebRequestBase) â the request object
path (str) â the path of the resource to publish. If empty, None or â/â âviewâ is used as the default path.
- Return type
tuple(str, cubicweb.rset.ResultSet or None)
- Returns
the publishing method identifier and an optional result set
- Raises
NotFound â if no handler is able to decode the given path
- class cubicweb_web.views.urlpublishing.URLPathEvaluator(urlpublisher)[source]#
Bases:
cubicweb_web.view.Component
- class cubicweb_web.views.urlpublishing.RawPathEvaluator(urlpublisher)[source]#
Bases:
cubicweb_web.views.urlpublishing.URLPathEvaluator
handle path of the form:
<publishing_method>?parameters...
- class cubicweb_web.views.urlpublishing.EidPathEvaluator(urlpublisher)[source]#
Bases:
cubicweb_web.views.urlpublishing.URLPathEvaluator
handle path with the form:
<eid>
- class cubicweb_web.views.urlpublishing.RestPathEvaluator(urlpublisher)[source]#
Bases:
cubicweb_web.views.urlpublishing.URLPathEvaluator
handle path with the form:
<etype>[[/<attribute name>]/<attribute value>]*
- class cubicweb_web.views.urlpublishing.URLRewriteEvaluator(urlpublisher)[source]#
Bases:
cubicweb_web.views.urlpublishing.URLPathEvaluator
tries to find a rewrite rule to apply
URL rewrite rule definitions are stored in URLRewriter objects
- class cubicweb_web.views.urlpublishing.ActionPathEvaluator(urlpublisher)[source]#
Bases:
cubicweb_web.views.urlpublishing.URLPathEvaluator
handle path with the form:
<any evaluator path>/<action>