[MERGE] Merge from openerp-web.

bzr revid: jra@tinyerp.com-20110926054324-4j7ae515cue29hx8
This commit is contained in:
Jiten (OpenERP)
2011-09-26 11:13:24 +05:30
6 changed files with 84 additions and 50 deletions
+6 -7
View File
@@ -2,27 +2,26 @@ import common
import controllers
import common.dispatch
import logging
import optparse
_logger = logging.getLogger(__name__)
class Options(object):
pass
def wsgi_postload():
import openerp.wsgi
import openerp.tools
import os
import tempfile
_logger.info("embedded mode")
class Options(object):
pass
o = Options()
o.dbfilter = '.*'
o.dbfilter = openerp.tools.config['dbfilter']
o.session_storage = os.path.join(tempfile.gettempdir(), "oe-sessions")
o.addons_path = os.path.dirname(os.path.dirname(__file__))
o.serve_static = True
o.backend = 'local'
app = common.dispatch.Root(o)
#import openerp.wsgi
openerp.wsgi.register_wsgi_handler(app)
# TODO
# if we detect that we are imported from the openerp server register common.Root() as a wsgi entry point
+8 -11
View File
@@ -21,8 +21,7 @@ import werkzeug.wsgi
import ast
import nonliterals
import http
# import backendlocal as backend
import session as backend
import session
import openerplib
__all__ = ['Root', 'jsonrequest', 'httprequest', 'Controller',
@@ -79,12 +78,12 @@ class WebRequest(object):
.. attribute:: session_id
opaque identifier for the :class:`backend.OpenERPSession` instance of
opaque identifier for the :class:`session.OpenERPSession` instance of
the current request
.. attribute:: session
:class:`~backend.OpenERPSession` instance for the current request
:class:`~session.OpenERPSession` instance for the current request
.. attribute:: context
@@ -100,13 +99,12 @@ class WebRequest(object):
self.httpresponse = None
self.httpsession = request.session
self.config = config
def init(self, params):
self.params = dict(params)
# OpenERP session setup
self.session_id = self.params.pop("session_id", None) or uuid.uuid4().hex
self.session = self.httpsession.setdefault(
self.session_id, backend.OpenERPSession(
self.config.server_host, self.config.server_port))
self.session = self.httpsession.setdefault(self.session_id, session.OpenERPSession(self.config))
self.context = self.params.pop('context', None)
self.debug = self.params.pop('debug', False) != False
@@ -389,15 +387,14 @@ class Root(object):
for module in os.listdir(addons_path):
if module not in addons_module:
manifest_path = os.path.join(addons_path, module, '__openerp__.py')
if os.path.isfile(manifest_path):
path_static = os.path.join(addons_path, module, 'static')
if os.path.isfile(manifest_path) and os.path.isdir(path_static):
manifest = ast.literal_eval(open(manifest_path).read())
_logger.info("Loading %s", module)
m = __import__(module)
addons_module[module] = m
addons_manifest[module] = manifest
statics['/%s/static' % module] = \
os.path.join(addons_path, module, 'static')
statics['/%s/static' % module] = path_static
for k, v in controllers_class.items():
if k not in controllers_object:
o = v()
+33 -3
View File
@@ -190,6 +190,34 @@ class NetRPCConnector(Connector):
socket.disconnect()
return result
class LocalConnector(Connector):
"""
A type of connector that uses the XMLRPC protocol.
"""
PROTOCOL = 'local'
__logger = _getChildLogger(_logger, 'connector.local')
def __init__(self):
pass
def send(self, service_name, method, *args):
import openerp
# TODO Exception handling
# This will be changed to be xmlrpc compatible
# OpenERPWarning code 1
# OpenERPException code 2
try:
result = openerp.netsvc.dispatch_rpc(service_name, method, args, None)
except openerp.netsvc.OpenERPDispatcherException, e:
fault = xmlrpclib.Fault(openerp.tools.exception_to_unicode(e.exception), e.traceback)
raise fault
except:
exc_type, exc_value, exc_tb = sys.exc_info()
fault = xmlrpclib.Fault(1, "%s:%s" % (exc_type, exc_value))
raise fault
return result
class Service(object):
"""
A class to execute RPC calls on a specific service of the remote server.
@@ -363,7 +391,7 @@ class Model(object):
records = self.read(record_ids, fields or [], context or {})
return records
def get_connector(hostname, protocol="xmlrpc", port="auto"):
def get_connector(hostname=None, protocol="xmlrpc", port="auto"):
"""
A shortcut method to easily create a connector to a remote server using XMLRPC or NetRPC.
@@ -377,10 +405,12 @@ def get_connector(hostname, protocol="xmlrpc", port="auto"):
return XmlRPCConnector(hostname, port)
elif protocol == "netrpc":
return NetRPCConnector(hostname, port)
elif protocol == "local":
return LocalConnector()
else:
raise ValueError("You must choose xmlrpc or netrpc")
raise ValueError("You must choose xmlrpc or netrpc or local")
def get_connection(hostname, protocol="xmlrpc", port='auto', database=None,
def get_connection(hostname=None, protocol="xmlrpc", port='auto', database=None,
login=None, password=None, user_id=None):
"""
A shortcut method to easily create a connection to a remote OpenERP server.
+11 -7
View File
@@ -26,9 +26,8 @@ class OpenERPSession(object):
Used to store references to non-literal domains which need to be
round-tripped to the client browser.
"""
def __init__(self, server='127.0.0.1', port=8069):
self._server = server
self._port = port
def __init__(self, config):
self.config = config
self._db = False
self._uid = False
self._login = False
@@ -40,11 +39,16 @@ class OpenERPSession(object):
self._lang = {}
self.remote_timezone = 'utc'
self.client_timezone = False
def build_connection(self):
return openerplib.get_connection(hostname=self._server, port=self._port,
database=self._db, login=self._login,
user_id=self._uid, password=self._password)
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,
user_id=self._uid, password=self._password)
return conn
def proxy(self, service):
return self.build_connection().get_service(service)
-3
View File
@@ -1025,7 +1025,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
},
do_url_set_hash: function(url) {
if(!this.url_external_hashchange) {
console.log("url set #hash to",url);
this.url_internal_hashchange = true;
jQuery.bbq.pushState(url);
}
@@ -1033,10 +1032,8 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
on_url_hashchange: function() {
if(this.url_internal_hashchange) {
this.url_internal_hashchange = false;
console.log("url jump to FLAG OFF");
} else {
var url = jQuery.deparam.fragment();
console.log("url jump to",url);
this.url_external_hashchange = true;
this.action_manager.on_url_hashchange(url);
this.url_external_hashchange = false;
+26 -19
View File
@@ -15,8 +15,6 @@ if path_addons not in sys.path:
sys.path.insert(0, path_addons)
optparser = optparse.OptionParser()
optparser.add_option("-p", "--port", dest="socket_port", default=8002,
help="listening port", type="int", metavar="NUMBER")
optparser.add_option("-s", "--session-path", dest="session_storage",
default=os.path.join(tempfile.gettempdir(), "oe-sessions"),
help="directory used for session storage", metavar="DIR")
@@ -28,28 +26,37 @@ optparser.add_option("--db-filter", dest="dbfilter", default='.*',
help="Filter listed database", metavar="REGEXP")
optparser.add_option('--addons-path', dest='addons_path', default=path_addons,
help="Path do addons directory", metavar="PATH")
optparser.add_option('--no-serve-static', dest='serve_static',
default=True, action='store_false',
help="Do not serve static files via this server")
optparser.add_option('--reloader', dest='reloader',
default=False, action='store_true',
help="Reload application when python files change")
optparser.add_option("--log-level", dest="log_level",
default='debug', help="Log level", metavar="LOG_LEVEL")
optparser.add_option("--log-config", dest="log_config",
default='', help="Log config file", metavar="LOG_CONFIG")
optparser.add_option('--multi-threaded', dest='threaded',
default=False, action='store_true',
help="Use multiple threads to handle requests")
optparser.add_option('--proxy-mode', dest='proxy_mode',
default=False, action='store_true',
help="Enable correct behavior when behind a reverse Proxy")
server_options = optparse.OptionGroup(optparser, "Server configuration")
server_options.add_option("-p", "--port", dest="socket_port", default=8002,
help="listening port", type="int", metavar="NUMBER")
server_options.add_option('--reloader', dest='reloader',
default=False, action='store_true',
help="Reload application when python files change")
server_options.add_option('--no-serve-static', dest='serve_static',
default=True, action='store_false',
help="Do not serve static files via this server")
server_options.add_option('--multi-threaded', dest='threaded',
default=False, action='store_true',
help="Spawn one thread per HTTP request")
server_options.add_option('--proxy-mode', dest='proxy_mode',
default=False, action='store_true',
help="Enable correct behavior when behind a reverse proxy")
optparser.add_option_group(server_options)
logging_opts = optparse.OptionGroup(optparser, "Logging")
logging_opts.add_option("--log-level", dest="log_level", type="choice",
default='debug', help="Global logging level", metavar="LOG_LEVEL",
choices=['debug', 'info', 'warning', 'error', 'critical'])
logging_opts.add_option("--log-config", dest="log_config",
help="Logging configuration file", metavar="FILE")
optparser.add_option_group(logging_opts)
import web.common.dispatch
if __name__ == "__main__":
(options, args) = optparser.parse_args(sys.argv[1:])
options.backend = 'rpc'
options.backend = 'xmlrpc'
os.environ["TZ"] = "UTC"