[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

authorpierre-yves
changeseta1cee6915ea3
branchdefault
phasepublic
hiddenno
parent revision#d8806996ac01 [connection] add logging method on connection
child revision#67f242261dd3 [connection] give access to is_internal_session boolean
files modified by this revision
dbapi.py
req.py
server/session.py
web/request.py
# HG changeset patch
# User pierre-yves
# Date 1371209989 -7200
# Fri Jun 14 13:39:49 2013 +0200
# Node ID a1cee6915ea395d69b4ffa6390a57a073871d0a7
# Parent d8806996ac0166c2598da51c38ed5b50e33488d7
[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

diff --git a/dbapi.py b/dbapi.py
@@ -329,13 +329,10 @@
1              # established
2              self.session = None
3              self.cnx = self.user = _NeedAuthAccessMock()
4          self.set_default_language(vreg)
5 
6 -    def from_controller(self):
7 -        return 'view'
8 -
9      def get_option_value(self, option, foreid=None):
10          return self.cnx.get_option_value(option, foreid)
11 
12      def set_session(self, session, user=None):
13          """method called by the session handler when the user is authenticated
diff --git a/req.py b/req.py
@@ -219,28 +219,24 @@
14 
15          raises :exc:`ValueError` if None is found in arguments
16          """
17          # use *args since we don't want first argument to be "anonymous" to
18          # avoid potential clash with kwargs
19 +        method = None
20          if args:
21              assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
22              method = args[0]
23 -        else:
24 -            method = None
25 +        if method is None:
26 +            method = 'view'
27          # XXX I (adim) think that if method is passed explicitly, we should
28          #     not try to process it and directly call req.build_url()
29 -        if method is None:
30 -            if self.from_controller() == 'view' and not '_restpath' in kwargs:
31 -                method = self.relative_path(includeparams=False) or 'view'
32 -            else:
33 -                method = 'view'
34          base_url = kwargs.pop('base_url', None)
35          if base_url is None:
36              secure = kwargs.pop('__secure__', None)
37              base_url = self.base_url(secure=secure)
38          if '_restpath' in kwargs:
39 -            assert method == 'view', method
40 +            assert method == 'view', repr(method)
41              path = kwargs.pop('_restpath')
42          else:
43              path = method
44          if not kwargs:
45              return u'%s%s' % (base_url, path)
diff --git a/server/session.py b/server/session.py
@@ -1148,16 +1148,10 @@
46      set_entity_cache  = cnx_meth('set_entity_cache')
47      entity_cache      = cnx_meth('entity_cache')
48      cache_entities    = cnx_meth('cached_entities')
49      drop_entity_cache = cnx_meth('drop_entity_cache')
50 
51 -    def from_controller(self):
52 -        """return the id (string) of the controller issuing the request (no
53 -        sense here, always return 'view')
54 -        """
55 -        return 'view'
56 -
57      source_defs = cnx_meth('source_defs')
58      describe = cnx_meth('describe')
59      source_from_eid = cnx_meth('source_from_eid')
60 
61 
diff --git a/web/request.py b/web/request.py
@@ -729,10 +729,16 @@
62          publishing method to use may be specified or will be guessed.
63          """
64          if '__message' in kwargs:
65              msg = kwargs.pop('__message')
66              kwargs['_cwmsgid'] = self.set_redirect_message(msg)
67 +        if not args:
68 +            method = 'view'
69 +            if (self.from_controller() == 'view'
70 +                and not '_restpath' in kwargs):
71 +                method = self.relative_path(includeparams=False) or 'view'
72 +            args = (method,)
73          return super(CubicWebRequestBase, self).build_url(*args, **kwargs)
74 
75      def url(self, includeparams=True):
76          """return currently accessed url"""
77          return self.base_url() + self.relative_path(includeparams)