summaryrefslogtreecommitdiff
path: root/addons/web/common
diff options
context:
space:
mode:
authorVidhin Mehta (OpenERP) <vme@tinyerp.com>2011-10-25 16:55:48 +0530
committerVidhin Mehta (OpenERP) <vme@tinyerp.com>2011-10-25 16:55:48 +0530
commitc17c8a0bd10d5c9cedd6c34bc0110c02ecdcd6b2 (patch)
treeb4543c28941307f8ebdd60191f2eb2494139aad2 /addons/web/common
parent1ee677eadbfa3e4c7d9836c48bea735f41f6a5a7 (diff)
parent55ad46220db83d2f5d6dd86d243d0d9843b74511 (diff)
[IMP]merge with main branch of view editor.
bzr revid: vme@tinyerp.com-20111025112548-eakr7fio6diovn2m
Diffstat (limited to 'addons/web/common')
-rw-r--r--addons/web/common/http.py38
-rw-r--r--addons/web/common/nonliterals.py22
-rw-r--r--addons/web/common/openerplib/main.py2
3 files changed, 50 insertions, 12 deletions
diff --git a/addons/web/common/http.py b/addons/web/common/http.py
index 453484acee7..e23a0431a7c 100644
--- a/addons/web/common/http.py
+++ b/addons/web/common/http.py
@@ -227,7 +227,7 @@ class HttpRequest(WebRequest):
_logger.debug("%s --> %s.%s %r", self.httprequest.method, controller.__class__.__name__, method.__name__, akw)
r = method(controller, self, **self.params)
if self.debug or 1:
- if isinstance(r, werkzeug.wrappers.BaseResponse):
+ if isinstance(r, (werkzeug.wrappers.BaseResponse, werkzeug.exceptions.HTTPException)):
_logger.debug('<-- %s', r)
else:
_logger.debug("<-- size: %s", len(r))
@@ -296,6 +296,35 @@ def session_context(request, storage_path, session_cookie='sessionid'):
try:
yield request.session
finally:
+ # Remove all OpenERPSession instances with no uid, they're generated
+ # either by login process or by HTTP requests without an OpenERP
+ # session id, and are generally noise
+ for key, value in request.session.items():
+ if isinstance(value, session.OpenERPSession) and not value._uid:
+ del request.session[key]
+
+ # FIXME: remove this when non-literals disappear
+ if sid:
+ # Re-load sessions from storage and merge non-literal
+ # contexts and domains (they're indexed by hash of the
+ # content so conflicts should auto-resolve), otherwise if
+ # two requests alter those concurrently the last to finish
+ # will overwrite the previous one, leading to loss of data
+ # (a non-literal is lost even though it was sent to the
+ # client and client errors)
+ #
+ # note that domains_store and contexts_store are append-only (we
+ # only ever add items to them), so we can just update one with the
+ # other to get the right result, if we want to merge the
+ # ``context`` dict we'll need something smarter
+ in_store = session_store.get(sid)
+ for k, v in request.session.iteritems():
+ stored = in_store.get(k)
+ if stored and isinstance(v, session.OpenERPSession)\
+ and v != stored:
+ v.contexts_store.update(stored.contexts_store)
+ v.domains_store.update(stored.domains_store)
+
session_store.save(request.session)
#----------------------------------------------------------
@@ -395,7 +424,8 @@ class Root(object):
else:
response = result
- response.set_cookie(self.session_cookie, session.sid)
+ if hasattr(response, 'set_cookie'):
+ response.set_cookie(self.session_cookie, session.sid)
return response(environ, start_response)
@@ -437,8 +467,8 @@ class Root(object):
:returns: a callable matching the path sections, or ``None``
:rtype: ``Controller | None``
"""
- if len(l) > 1:
- for i in range(len(l), 1, -1):
+ if len(l):
+ for i in range(len(l), 0, -1):
ps = "/" + "/".join(l[0:i])
if ps in controllers_path:
c = controllers_path[ps]
diff --git a/addons/web/common/nonliterals.py b/addons/web/common/nonliterals.py
index 986ca36cb2f..f6e81894a4c 100644
--- a/addons/web/common/nonliterals.py
+++ b/addons/web/common/nonliterals.py
@@ -21,12 +21,14 @@ class NonLiteralEncoder(simplejson.encoder.JSONEncoder):
if isinstance(object, Domain):
return {
'__ref': 'domain',
- '__id': object.key
+ '__id': object.key,
+ '__debug': object.get_domain_string()
}
elif isinstance(object, Context):
return {
'__ref': 'context',
- '__id': object.key
+ '__id': object.key,
+ '__debug': object.get_context_string()
}
elif isinstance(object, CompoundDomain):
return {
@@ -42,7 +44,7 @@ class NonLiteralEncoder(simplejson.encoder.JSONEncoder):
}
raise TypeError('Could not encode unknown non-literal %s' % object)
-_ALLOWED_KEYS = frozenset(['__ref', "__id", '__domains',
+_ALLOWED_KEYS = frozenset(['__ref', "__id", '__domains', '__debug',
'__contexts', '__eval_context', 'own_values'])
def non_literal_decoder(dct):
@@ -53,8 +55,8 @@ def non_literal_decoder(dct):
``own_values`` dict key.
"""
if '__ref' in dct:
- for x in dct.keys():
- if not x in _ALLOWED_KEYS:
+ for x in dct:
+ if x not in _ALLOWED_KEYS:
raise ValueError("'%s' key not allowed in non literal domain/context" % x)
if dct['__ref'] == 'domain':
domain = Domain(None, key=dct['__id'])
@@ -131,7 +133,10 @@ class Domain(BaseDomain):
ctx = self.session.evaluation_context(context)
if self.own:
ctx.update(self.own)
- return eval(self.get_domain_string(), SuperDict(ctx))
+ try:
+ return eval(self.get_domain_string(), SuperDict(ctx))
+ except NameError as e:
+ raise ValueError('Error during evaluation of this domain: "%s", message: "%s"' % (self.get_domain_string(), e.message))
class Context(BaseContext):
def __init__(self, session, context_string=None, key=None):
@@ -176,7 +181,10 @@ class Context(BaseContext):
ctx = self.session.evaluation_context(context)
if self.own:
ctx.update(self.own)
- return eval(self.get_context_string(), SuperDict(ctx))
+ try:
+ return eval(self.get_context_string(), SuperDict(ctx))
+ except NameError as e:
+ raise ValueError('Error during evaluation of this context: "%s", message: "%s"' % (self.get_context_string(), e.message))
class SuperDict(dict):
def __getattr__(self, name):
diff --git a/addons/web/common/openerplib/main.py b/addons/web/common/openerplib/main.py
index 217cb221cd9..5cae9ce4636 100644
--- a/addons/web/common/openerplib/main.py
+++ b/addons/web/common/openerplib/main.py
@@ -350,7 +350,7 @@ class Connection(object):
return
if not self.database or not self.login or self.password is None:
- raise AuthenticationError("Creditentials not provided")
+ raise AuthenticationError("Credentials not provided")
self.user_id = self.get_service("common").login(self.database, self.login, self.password)
if not self.user_id: