equal
deleted
inserted
replaced
57 """ |
57 """ |
58 __docformat__ = "restructuredtext en" |
58 __docformat__ = "restructuredtext en" |
59 |
59 |
60 from rql import TypeResolverException |
60 from rql import TypeResolverException |
61 |
61 |
62 from cubicweb import RegistryException, typed_eid |
62 from cubicweb import RegistryException |
63 from cubicweb.web import NotFound, Redirect, component |
63 from cubicweb.web import NotFound, Redirect, component |
64 |
64 |
65 |
65 |
66 class PathDontMatch(Exception): |
66 class PathDontMatch(Exception): |
67 """exception used by url evaluators to notify they can't evaluate |
67 """exception used by url evaluators to notify they can't evaluate |
163 priority = 1 |
163 priority = 1 |
164 def evaluate_path(self, req, parts): |
164 def evaluate_path(self, req, parts): |
165 if len(parts) != 1: |
165 if len(parts) != 1: |
166 raise PathDontMatch() |
166 raise PathDontMatch() |
167 try: |
167 try: |
168 rset = req.execute('Any X WHERE X eid %(x)s', {'x': typed_eid(parts[0])}) |
168 rset = req.execute('Any X WHERE X eid %(x)s', {'x': int(parts[0])}) |
169 except ValueError: |
169 except ValueError: |
170 raise PathDontMatch() |
170 raise PathDontMatch() |
171 if rset.rowcount == 0: |
171 if rset.rowcount == 0: |
172 raise NotFound() |
172 raise NotFound() |
173 return None, rset |
173 return None, rset |
220 st = cls.fetch_rqlst(req.user, ordermethod=None) |
220 st = cls.fetch_rqlst(req.user, ordermethod=None) |
221 st.add_constant_restriction(st.get_variable('X'), attrname, |
221 st.add_constant_restriction(st.get_variable('X'), attrname, |
222 'x', 'Substitute') |
222 'x', 'Substitute') |
223 if attrname == 'eid': |
223 if attrname == 'eid': |
224 try: |
224 try: |
225 rset = req.execute(st.as_string(), {'x': typed_eid(value)}) |
225 rset = req.execute(st.as_string(), {'x': int(value)}) |
226 except (ValueError, TypeResolverException): |
226 except (ValueError, TypeResolverException): |
227 # conflicting eid/type |
227 # conflicting eid/type |
228 raise PathDontMatch() |
228 raise PathDontMatch() |
229 else: |
229 else: |
230 rset = req.execute(st.as_string(), {'x': value}) |
230 rset = req.execute(st.as_string(), {'x': value}) |