[req] drop from_controller on non WebRequest object (Closes #2901079)
authorpierre-yves
Fri, 14 Jun 2013 13:39:49 +0200
changeset 9022 a1cee6915ea3
parent 9021 d8806996ac01
child 9023 67f242261dd3
[req] drop from_controller on non WebRequest object (Closes #2901079) The `controller` concept is purely a web things. It does not belong to generic `req` object. The `build_url` code is slightly changed to handle that. This probably requires extended cleanup later. This is a barely used and very internal API. No deprecation period
dbapi.py
req.py
server/session.py
web/request.py
--- a/dbapi.py	Tue May 14 00:36:43 2013 +0200
+++ b/dbapi.py	Fri Jun 14 13:39:49 2013 +0200
@@ -331,9 +331,6 @@
             self.cnx = self.user = _NeedAuthAccessMock()
         self.set_default_language(vreg)
 
-    def from_controller(self):
-        return 'view'
-
     def get_option_value(self, option, foreid=None):
         return self.cnx.get_option_value(option, foreid)
 
--- a/req.py	Tue May 14 00:36:43 2013 +0200
+++ b/req.py	Fri Jun 14 13:39:49 2013 +0200
@@ -221,24 +221,20 @@
         """
         # use *args since we don't want first argument to be "anonymous" to
         # avoid potential clash with kwargs
+        method = None
         if args:
             assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
             method = args[0]
-        else:
-            method = None
+        if method is None:
+            method = 'view'
         # XXX I (adim) think that if method is passed explicitly, we should
         #     not try to process it and directly call req.build_url()
-        if method is None:
-            if self.from_controller() == 'view' and not '_restpath' in kwargs:
-                method = self.relative_path(includeparams=False) or 'view'
-            else:
-                method = 'view'
         base_url = kwargs.pop('base_url', None)
         if base_url is None:
             secure = kwargs.pop('__secure__', None)
             base_url = self.base_url(secure=secure)
         if '_restpath' in kwargs:
-            assert method == 'view', method
+            assert method == 'view', repr(method)
             path = kwargs.pop('_restpath')
         else:
             path = method
--- a/server/session.py	Tue May 14 00:36:43 2013 +0200
+++ b/server/session.py	Fri Jun 14 13:39:49 2013 +0200
@@ -1150,12 +1150,6 @@
     cache_entities    = cnx_meth('cached_entities')
     drop_entity_cache = cnx_meth('drop_entity_cache')
 
-    def from_controller(self):
-        """return the id (string) of the controller issuing the request (no
-        sense here, always return 'view')
-        """
-        return 'view'
-
     source_defs = cnx_meth('source_defs')
     describe = cnx_meth('describe')
     source_from_eid = cnx_meth('source_from_eid')
--- a/web/request.py	Tue May 14 00:36:43 2013 +0200
+++ b/web/request.py	Fri Jun 14 13:39:49 2013 +0200
@@ -731,6 +731,12 @@
         if '__message' in kwargs:
             msg = kwargs.pop('__message')
             kwargs['_cwmsgid'] = self.set_redirect_message(msg)
+        if not args:
+            method = 'view'
+            if (self.from_controller() == 'view'
+                and not '_restpath' in kwargs):
+                method = self.relative_path(includeparams=False) or 'view'
+            args = (method,)
         return super(CubicWebRequestBase, self).build_url(*args, **kwargs)
 
     def url(self, includeparams=True):