--- a/doc/book/en/devweb/views/urlpublish.rst Fri Oct 28 11:44:50 2011 +0200
+++ b/doc/book/en/devweb/views/urlpublish.rst Fri Oct 28 12:07:37 2011 +0200
@@ -10,6 +10,70 @@
.. autoclass:: cubicweb.web.views.urlpublishing.URLPublisherComponent
:members:
+
+You can write your own *URLPathEvaluator* class to handle custom paths.
+For instance, if you want */my-card-id* to redirect to the corresponding
+card's primary view, you would write:
+
+.. sourcecode:: python
+
+ class CardWikiidEvaluator(URLPathEvaluator):
+ priority = 3 # make it be evaluated *before* RestPathEvaluator
+
+ def evaluate_path(self, req, segments):
+ if len(segments) != 1:
+ raise PathDontMatch()
+ rset = req.execute('Any C WHERE C wikiid %(w)s',
+ {'w': segments[0]})
+ if len(rset) == 0:
+ # Raise NotFound if no card is found
+ raise PathDontMatch()
+ return None, rset
+
+On the other hand, you can also deactivate some of the standard
+evaluators in your final application. The only thing you have to
+do is to unregister them, for instance in a *registration_callback*
+in your cube:
+
+.. sourcecode:: python
+
+ def registration_callback(vreg):
+ vreg.unregister(RestPathEvaluator)
+
+You can even replace the :class:`cubicweb.web.views.urlpublishing.URLPublisherComponent`
+class if you want to customize the whole toolchain process or if you want
+to plug into an early enough extension point to control your request
+parameters:
+
+.. sourcecode:: python
+
+ class SanitizerPublisherComponent(URLPublisherComponent):
+ """override default publisher component to explicitly ignore
+ unauthorized request parameters in anonymous mode.
+ """
+ unauthorized_form_params = ('rql', 'vid', '__login', '__password')
+
+ def process(self, req, path):
+ if req.session.anonymous_session:
+ self._remove_unauthorized_params(req)
+ return super(SanitizerPublisherComponent, self).process(req, path)
+
+ def _remove_unauthorized_params(self, req):
+ for param in req.form.keys():
+ if param in self.unauthorized_form_params:
+ req.form.pop(param)
+
+
+ def registration_callback(vreg):
+ vreg.register_and_replace(SanitizerPublisherComponent, URLPublisherComponent)
+
+
+.. autoclass:: cubicweb.web.views.urlpublishing.RawPathEvaluator
+.. autoclass:: cubicweb.web.views.urlpublishing.EidPathEvaluator
+.. autoclass:: cubicweb.web.views.urlpublishing.URLRewriteEvaluator
+.. autoclass:: cubicweb.web.views.urlpublishing.RestPathEvaluator
+.. autoclass:: cubicweb.web.views.urlpublishing.ActionPathEvaluator
+
URL rewriting
-------------