diff --git a/addons/web/common/dispatch.py b/addons/web/common/dispatch.py index 7a293c8228b..57e45fa594e 100644 --- a/addons/web/common/dispatch.py +++ b/addons/web/common/dispatch.py @@ -311,6 +311,13 @@ class Root(object): def __init__(self, options): self.root = werkzeug.urls.Href('/web/webclient/home') self.config = options + + if self.config.backend == 'local': + conn = openerplib.get_connector(protocol='local') + else: + conn = openerplib.get_connector(hostname=self.config.server_host, + port=self.config.server_port) + self.config.connector = conn self.session_cookie = 'sessionid' self.addons = {} diff --git a/addons/web/common/openerplib/main.py b/addons/web/common/openerplib/main.py index ffe7d3c2d8b..b09e9f9d72f 100644 --- a/addons/web/common/openerplib/main.py +++ b/addons/web/common/openerplib/main.py @@ -71,6 +71,14 @@ class Connector(object): self.hostname = hostname self.port = port + def get_service(self, service_name): + """ + Returns a Service instance to allow easy manipulation of one of the services offered by the remote server. + + :param service_name: The name of the service. + """ + return Service(self, service_name) + class XmlRPCConnector(Connector): """ A type of connector that uses the XMLRPC protocol. @@ -321,7 +329,7 @@ class Connection(object): :param service_name: The name of the service. """ - return Service(self.connector, service_name) + return self.connector.get_service(service_name) class AuthenticationError(Exception): """ diff --git a/addons/web/common/session.py b/addons/web/common/session.py index c06763bebe2..d4265851acc 100644 --- a/addons/web/common/session.py +++ b/addons/web/common/session.py @@ -5,6 +5,9 @@ import time import openerplib import nonliterals + +import logging +_logger = logging.getLogger(__name__) #---------------------------------------------------------- # OpenERPSession RPC openerp backend access #---------------------------------------------------------- @@ -41,12 +44,7 @@ class OpenERPSession(object): self.client_timezone = False def build_connection(self): - if self.config.backend == 'local': - conn = openerplib.get_connection(protocol='local', database=self._db, - login=self._login, user_id=self._uid, password=self._password) - else: - conn = openerplib.get_connection(hostname=self.config.server_host, - port=self.config.server_port, database=self._db, login=self._login, + conn = openerplib.Connection(self.config.connector, database=self._db, login=self._login, user_id=self._uid, password=self._password) return conn