[url publishing] fix regression introduced by refactoring in 3.9.7, leading to table view being choosen when one would expect the primary view. Fix similar pb with /<etype> url and list view (this one has been there for a while) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 16 Sep 2010 18:41:45 +0200
branchstable
changeset 6274 72bf3ec4068b
parent 6273 8dbdd4cc7938
child 6275 20f30e01ae59
[url publishing] fix regression introduced by refactoring in 3.9.7, leading to table view being choosen when one would expect the primary view. Fix similar pb with /<etype> url and list view (this one has been there for a while)
web/views/urlpublishing.py
--- a/web/views/urlpublishing.py	Thu Sep 16 18:39:35 2010 +0200
+++ b/web/views/urlpublishing.py	Thu Sep 16 18:41:45 2010 +0200
@@ -179,10 +179,19 @@
             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))
+    def set_vid_for_rset(self, req, cls, rset):# cls is there to ease overriding
         if rset.rowcount == 0:
             raise NotFound()
+        # we've to set a default vid here, since vid_from_rset may try to use a
+        # table view if fetch_rql include some non final relation
+        if rset.rowcount == 1:
+            req.form.setdefault('vid', 'primary')
+        else: # rset.rowcount >= 1
+            req.form.setdefault('vid', 'sameetypelist')
+
+    def handle_etype(self, req, cls):
+        rset = req.execute(cls.fetch_rql(req.user))
+        self.set_vid_for_rset(req, cls, rset)
         return None, rset
 
     def handle_etype_attr(self, req, cls, attrname, value):
@@ -196,8 +205,7 @@
                 raise PathDontMatch()
         else:
             rset = req.execute(rql, {'x': value})
-        if rset.rowcount == 0:
-            raise NotFound()
+        self.set_vid_for_rset(req, cls, rset)
         return None, rset