[urlpublishing] refactor to ease overriding stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 16 Sep 2010 11:26:08 +0200
branchstable
changeset 6253 30b6beb38820
parent 6252 d33509b79efe
child 6254 936e98213598
[urlpublishing] refactor to ease overriding
web/views/urlpublishing.py
--- a/web/views/urlpublishing.py	Thu Sep 16 11:25:17 2010 +0200
+++ b/web/views/urlpublishing.py	Thu Sep 16 11:26:08 2010 +0200
@@ -176,18 +176,18 @@
             else:
                 attrname = cls._rest_attr_info()[0]
             value = req.url_unquote(parts.pop(0))
-            rset = self.attr_rset(req, etype, attrname, value)
-        else:
-            rset = self.cls_rset(req, cls)
+            return self.handle_etype_attr(req, cls, attrname, value)
+        return self.handle_etype(req, cls)
+
+    def handle_etype(self, req, cls):
+        rset =  req.execute(cls.fetch_rql(req.user))
         if rset.rowcount == 0:
             raise NotFound()
         return None, rset
 
-    def cls_rset(self, req, cls):
-        return req.execute(cls.fetch_rql(req.user))
-
-    def attr_rset(self, req, etype, attrname, value):
-        rql = u'Any X WHERE X is %s, X %s %%(x)s' % (etype, attrname)
+    def handle_etype_attr(self, req, cls, attrname, value):
+        rql = cls.fetch_rql(req.user, ['X %s %%(x)s' % (attrname)],
+                            mainvar='X', ordermethod=None)
         if attrname == 'eid':
             try:
                 rset = req.execute(rql, {'x': typed_eid(value)})
@@ -196,7 +196,9 @@
                 raise PathDontMatch()
         else:
             rset = req.execute(rql, {'x': value})
-        return rset
+        if rset.rowcount == 0:
+            raise NotFound()
+        return None, rset
 
 
 class URLRewriteEvaluator(URLPathEvaluator):