author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 02 Jun 2010 15:29:18 +0200 | |
changeset 5633 | 879590c52679 |
parent 5426 | 0d4853a6e5ee |
child 6175 | 104453c4ed3e |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5301
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
18 |
"""Associate url's path to view identifier / rql queries. |
0 | 19 |
|
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
20 |
It currently handles url path with the forms: |
0 | 21 |
|
22 |
* <publishing_method> |
|
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
23 |
* minimal REST publishing: |
0 | 24 |
|
25 |
* <eid> |
|
26 |
* <etype>[/<attribute name>/<attribute value>]* |
|
27 |
* folder navigation |
|
28 |
||
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
29 |
You can actually control URL (more exactly path) resolution using an |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
30 |
URL path evaluator. |
0 | 31 |
|
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
32 |
.. note:: |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
33 |
|
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
34 |
Actionpath and Folderpath execute a query whose results is lost |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
35 |
because of redirecting instead of direct traversal. |
0 | 36 |
""" |
37 |
__docformat__ = "restructuredtext en" |
|
38 |
||
39 |
from rql import TypeResolverException |
|
40 |
||
41 |
from cubicweb import RegistryException, typed_eid |
|
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
42 |
from cubicweb.web import NotFound, Redirect, component |
0 | 43 |
|
44 |
||
45 |
class PathDontMatch(Exception): |
|
46 |
"""exception used by url evaluators to notify they can't evaluate |
|
47 |
a path |
|
48 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
49 |
|
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
50 |
class URLPublisherComponent(component.Component): |
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
51 |
"""Associate url path to view identifier / rql queries, by |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
52 |
applying a chain of urlpathevaluator components. |
0 | 53 |
|
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
54 |
An evaluator is a URLPathEvaluator subclass with an .evaluate_path |
0 | 55 |
method taking the request object and the path to publish as |
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
56 |
argument. It will either return a publishing method identifier |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
57 |
and an rql query on success or raise a `PathDontMatch` exception |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
58 |
on failure. URL evaluators are called according to their |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
59 |
`priority` attribute, with 0 as the greatest priority and greater |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
60 |
values as lower priority. The first evaluator returning a result |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
61 |
or raising something else than `PathDontMatch` will stop the |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
62 |
handlers chain. |
0 | 63 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2890
diff
changeset
|
64 |
__regid__ = 'urlpublisher' |
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
65 |
vreg = None # XXX necessary until property for deprecation warning is on appobject |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
66 |
|
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
67 |
def __init__(self, vreg, default_method='view'): |
0 | 68 |
super(URLPublisherComponent, self).__init__() |
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
69 |
self.vreg = vreg |
0 | 70 |
self.default_method = default_method |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
71 |
evaluators = [] |
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
72 |
for evaluatorcls in vreg['components']['urlpathevaluator']: |
0 | 73 |
# instantiation needed |
74 |
evaluator = evaluatorcls(self) |
|
75 |
evaluators.append(evaluator) |
|
76 |
self.evaluators = sorted(evaluators, key=lambda x: x.priority) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
77 |
|
0 | 78 |
def process(self, req, path): |
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
79 |
"""Given an url (essentialy caracterized by a path on the |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
80 |
server, but additional information may be found in the request |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
81 |
object), return a publishing method identifier |
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
82 |
(e.g. controller) and an optional result set. |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
83 |
|
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
84 |
:type req: `cubicweb.web.request.CubicWebRequestBase` |
0 | 85 |
:param req: the request object |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
86 |
|
0 | 87 |
:type path: str |
88 |
:param path: the path of the resource to publish |
|
89 |
||
5301
f4219a6e62e3
[doc/book] stuff a bit the publishing process (including various docstrings)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4252
diff
changeset
|
90 |
:rtype: tuple(str, `cubicweb.rset.ResultSet` or None) |
0 | 91 |
:return: the publishing method identifier and an optional result set |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
92 |
|
0 | 93 |
:raise NotFound: if no handler is able to decode the given path |
94 |
""" |
|
95 |
parts = [part for part in path.split('/') |
|
96 |
if part != ''] or (self.default_method,) |
|
97 |
if req.form.get('rql'): |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
98 |
if parts[0] in self.vreg['controllers']: |
0 | 99 |
return parts[0], None |
100 |
return 'view', None |
|
101 |
for evaluator in self.evaluators: |
|
102 |
try: |
|
103 |
pmid, rset = evaluator.evaluate_path(req, parts[:]) |
|
104 |
break |
|
105 |
except PathDontMatch: |
|
106 |
continue |
|
107 |
else: |
|
108 |
raise NotFound(path) |
|
109 |
if pmid is None: |
|
110 |
pmid = self.default_method |
|
111 |
return pmid, rset |
|
112 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
113 |
|
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
114 |
class URLPathEvaluator(component.Component): |
0 | 115 |
__abstract__ = True |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2890
diff
changeset
|
116 |
__regid__ = 'urlpathevaluator' |
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
117 |
vreg = None # XXX necessary until property for deprecation warning is on appobject |
0 | 118 |
|
119 |
def __init__(self, urlpublisher): |
|
120 |
self.urlpublisher = urlpublisher |
|
2887
1282dc6525c5
give vreg where we need it (eg no bound request)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
121 |
self.vreg = urlpublisher.vreg |
0 | 122 |
|
123 |
class RawPathEvaluator(URLPathEvaluator): |
|
124 |
"""handle path of the form:: |
|
125 |
||
126 |
<publishing_method>?parameters... |
|
127 |
""" |
|
128 |
priority = 0 |
|
129 |
def evaluate_path(self, req, parts): |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
130 |
if len(parts) == 1 and parts[0] in self.vreg['controllers']: |
0 | 131 |
return parts[0], None |
132 |
raise PathDontMatch() |
|
133 |
||
134 |
||
135 |
class EidPathEvaluator(URLPathEvaluator): |
|
136 |
"""handle path with the form:: |
|
137 |
||
138 |
<eid> |
|
139 |
""" |
|
140 |
priority = 1 |
|
141 |
def evaluate_path(self, req, parts): |
|
142 |
if len(parts) != 1: |
|
143 |
raise PathDontMatch() |
|
144 |
try: |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
145 |
rset = req.execute('Any X WHERE X eid %(x)s', {'x': typed_eid(parts[0])}) |
0 | 146 |
except ValueError: |
147 |
raise PathDontMatch() |
|
148 |
if rset.rowcount == 0: |
|
149 |
raise NotFound() |
|
150 |
return None, rset |
|
151 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
152 |
|
0 | 153 |
class RestPathEvaluator(URLPathEvaluator): |
154 |
"""handle path with the form:: |
|
155 |
||
156 |
<etype>[[/<attribute name>]/<attribute value>]* |
|
157 |
""" |
|
158 |
priority = 2 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
159 |
|
0 | 160 |
def evaluate_path(self, req, parts): |
161 |
if not (0 < len(parts) < 4): |
|
162 |
raise PathDontMatch() |
|
163 |
try: |
|
2273
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
164 |
etype = self.vreg.case_insensitive_etypes[parts.pop(0).lower()] |
0 | 165 |
except KeyError: |
166 |
raise PathDontMatch() |
|
2664
1578e1a57828
[we, test] more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
167 |
cls = self.vreg['etypes'].etype_class(etype) |
0 | 168 |
if parts: |
169 |
if len(parts) == 2: |
|
170 |
attrname = parts.pop(0).lower() |
|
171 |
try: |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2664
diff
changeset
|
172 |
cls.e_schema.subjrels[attrname] |
0 | 173 |
except KeyError: |
174 |
raise PathDontMatch() |
|
175 |
else: |
|
176 |
attrname = cls._rest_attr_info()[0] |
|
177 |
value = req.url_unquote(parts.pop(0)) |
|
178 |
rset = self.attr_rset(req, etype, attrname, value) |
|
179 |
else: |
|
180 |
rset = self.cls_rset(req, cls) |
|
181 |
if rset.rowcount == 0: |
|
182 |
raise NotFound() |
|
183 |
return None, rset |
|
184 |
||
185 |
def cls_rset(self, req, cls): |
|
186 |
return req.execute(cls.fetch_rql(req.user)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
187 |
|
0 | 188 |
def attr_rset(self, req, etype, attrname, value): |
189 |
rql = u'Any X WHERE X is %s, X %s %%(x)s' % (etype, attrname) |
|
190 |
if attrname == 'eid': |
|
191 |
try: |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
192 |
rset = req.execute(rql, {'x': typed_eid(value)}) |
0 | 193 |
except (ValueError, TypeResolverException): |
194 |
# conflicting eid/type |
|
195 |
raise PathDontMatch() |
|
196 |
else: |
|
197 |
rset = req.execute(rql, {'x': value}) |
|
198 |
return rset |
|
199 |
||
200 |
||
201 |
class URLRewriteEvaluator(URLPathEvaluator): |
|
202 |
"""tries to find a rewrite rule to apply |
|
203 |
||
204 |
URL rewrite rule definitions are stored in URLRewriter objects |
|
205 |
""" |
|
206 |
priority = 3 |
|
207 |
def evaluate_path(self, req, parts): |
|
208 |
# uri <=> req._twreq.path or req._twreq.uri |
|
209 |
uri = req.url_unquote('/' + '/'.join(parts)) |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
210 |
evaluators = sorted(self.vreg['urlrewriting'].all_objects(), |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
211 |
key=lambda x: x.priority, reverse=True) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
212 |
for rewritercls in evaluators: |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2887
diff
changeset
|
213 |
rewriter = rewritercls(req) |
0 | 214 |
try: |
215 |
# XXX we might want to chain url rewrites |
|
216 |
return rewriter.rewrite(req, uri) |
|
217 |
except KeyError: |
|
218 |
continue |
|
219 |
raise PathDontMatch() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
220 |
|
0 | 221 |
|
222 |
class ActionPathEvaluator(URLPathEvaluator): |
|
223 |
"""handle path with the form:: |
|
224 |
||
225 |
<any evaluator path>/<action> |
|
226 |
""" |
|
227 |
priority = 4 |
|
228 |
def evaluate_path(self, req, parts): |
|
229 |
if len(parts) < 2: |
|
230 |
raise PathDontMatch() |
|
231 |
# remove last part and see if this is something like an actions |
|
232 |
# if so, call |
|
2770
356e9d7c356d
R propagate registry API changes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2664
diff
changeset
|
233 |
# XXX bad smell: refactor to simpler code |
0 | 234 |
try: |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
235 |
actionsreg = self.vreg['actions'] |
0 | 236 |
requested = parts.pop(-1) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
237 |
actions = actionsreg[requested] |
0 | 238 |
except RegistryException: |
239 |
raise PathDontMatch() |
|
240 |
for evaluator in self.urlpublisher.evaluators: |
|
241 |
if evaluator is self or evaluator.priority == 0: |
|
242 |
continue |
|
243 |
try: |
|
244 |
pmid, rset = evaluator.evaluate_path(req, parts[:]) |
|
245 |
except PathDontMatch: |
|
246 |
continue |
|
247 |
else: |
|
248 |
try: |
|
2770
356e9d7c356d
R propagate registry API changes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2664
diff
changeset
|
249 |
action = actionsreg._select_best(actions, req, rset=rset) |
0 | 250 |
except RegistryException: |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
251 |
continue |
0 | 252 |
else: |
253 |
# XXX avoid redirect |
|
254 |
raise Redirect(action.url()) |
|
255 |
raise PathDontMatch() |