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:

  1. 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;
  2. cubicweb.web.views.urlpublishing.EidPathEvaluator handles unique url segments that are eids (e.g. /1234);
  3. cubicweb.web.views.urlpublishing.URLRewriteEvaluator selects all urlrewriter components, sorts them according to their priority, call their rewrite() method, the first one that doesn’t raise a KeyError wins. This is where the cubicweb.web.views.urlrewrite and cubicweb.web.views.urlrewrite.SimpleReqRewriter comes into play;
  4. cubicweb.web.views.urlpublishing.RestPathEvaluator handles urls based on entity types and attributes : <etype>((/<attribute name>])?/<attribute value>)? This is why cwuser/carlos works;
  5. 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.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.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>

Previous topic

cubicweb.rset

Next topic

cubicweb.web.views.urlrewrite