7 |
7 |
8 .. automodule:: cubicweb.web.views.urlpublishing |
8 .. automodule:: cubicweb.web.views.urlpublishing |
9 |
9 |
10 .. autoclass:: cubicweb.web.views.urlpublishing.URLPublisherComponent |
10 .. autoclass:: cubicweb.web.views.urlpublishing.URLPublisherComponent |
11 :members: |
11 :members: |
|
12 |
|
13 |
|
14 You can write your own *URLPathEvaluator* class to handle custom paths. |
|
15 For instance, if you want */my-card-id* to redirect to the corresponding |
|
16 card's primary view, you would write: |
|
17 |
|
18 .. sourcecode:: python |
|
19 |
|
20 class CardWikiidEvaluator(URLPathEvaluator): |
|
21 priority = 3 # make it be evaluated *before* RestPathEvaluator |
|
22 |
|
23 def evaluate_path(self, req, segments): |
|
24 if len(segments) != 1: |
|
25 raise PathDontMatch() |
|
26 rset = req.execute('Any C WHERE C wikiid %(w)s', |
|
27 {'w': segments[0]}) |
|
28 if len(rset) == 0: |
|
29 # Raise NotFound if no card is found |
|
30 raise PathDontMatch() |
|
31 return None, rset |
|
32 |
|
33 On the other hand, you can also deactivate some of the standard |
|
34 evaluators in your final application. The only thing you have to |
|
35 do is to unregister them, for instance in a *registration_callback* |
|
36 in your cube: |
|
37 |
|
38 .. sourcecode:: python |
|
39 |
|
40 def registration_callback(vreg): |
|
41 vreg.unregister(RestPathEvaluator) |
|
42 |
|
43 You can even replace the :class:`cubicweb.web.views.urlpublishing.URLPublisherComponent` |
|
44 class if you want to customize the whole toolchain process or if you want |
|
45 to plug into an early enough extension point to control your request |
|
46 parameters: |
|
47 |
|
48 .. sourcecode:: python |
|
49 |
|
50 class SanitizerPublisherComponent(URLPublisherComponent): |
|
51 """override default publisher component to explicitly ignore |
|
52 unauthorized request parameters in anonymous mode. |
|
53 """ |
|
54 unauthorized_form_params = ('rql', 'vid', '__login', '__password') |
|
55 |
|
56 def process(self, req, path): |
|
57 if req.session.anonymous_session: |
|
58 self._remove_unauthorized_params(req) |
|
59 return super(SanitizerPublisherComponent, self).process(req, path) |
|
60 |
|
61 def _remove_unauthorized_params(self, req): |
|
62 for param in req.form.keys(): |
|
63 if param in self.unauthorized_form_params: |
|
64 req.form.pop(param) |
|
65 |
|
66 |
|
67 def registration_callback(vreg): |
|
68 vreg.register_and_replace(SanitizerPublisherComponent, URLPublisherComponent) |
|
69 |
|
70 |
|
71 .. autoclass:: cubicweb.web.views.urlpublishing.RawPathEvaluator |
|
72 .. autoclass:: cubicweb.web.views.urlpublishing.EidPathEvaluator |
|
73 .. autoclass:: cubicweb.web.views.urlpublishing.URLRewriteEvaluator |
|
74 .. autoclass:: cubicweb.web.views.urlpublishing.RestPathEvaluator |
|
75 .. autoclass:: cubicweb.web.views.urlpublishing.ActionPathEvaluator |
12 |
76 |
13 URL rewriting |
77 URL rewriting |
14 ------------- |
78 ------------- |
15 |
79 |
16 (:mod:`cubicweb.web.views.urlrewrite`) |
80 (:mod:`cubicweb.web.views.urlrewrite`) |