diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 4e2163c196e..51d7ed91547 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -171,12 +171,9 @@ class Session(openerpweb.Controller): a list of fields to group by, potentially empty (in which case no group by should be performed) """ - contexts = contexts or [] - domains = domains or [] - e_context = dict(reduce(lambda x, y: x + y, [openerpweb.nonliterals.get_eval_context(x).items() for x in contexts])) context, domain = eval_context_and_domain(req.session, - openerpweb.nonliterals.CompoundContext(*contexts).set_eval_context(e_context), - openerpweb.nonliterals.CompoundDomain(*domains)) + openerpweb.nonliterals.CompoundContext(*(contexts or [])), + openerpweb.nonliterals.CompoundDomain(*(domains or []))) group_by_sequence = [] for candidate in (group_by_seq or []): @@ -237,8 +234,7 @@ class Session(openerpweb.Controller): def eval_context_and_domain(session, context, domain=None): e_context = session.eval_context(context) - eval_context = openerpweb.nonliterals.get_eval_context(context) - e_domain = session.eval_domain(domain or [], dict(eval_context.items() + e_context.items())) + e_domain = session.eval_domain(domain or [], e_context) return (e_context, e_domain) diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index d9b2ca752c2..9f5792bfb24 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -597,10 +597,7 @@ openerp.base.CompoundContext = function() { }); }; openerp.base.CompoundContext.prototype.add = function(context) { - if (context.__ref === "compound_context") - this.__contexts = this.__contexts.concat(context.__contexts); - else - this.__contexts.push(context); + this.__contexts.push(context); return this; }; openerp.base.CompoundContext.prototype.set_eval_context = function(eval_context) { @@ -614,17 +611,22 @@ openerp.base.CompoundContext.prototype.get_eval_context = function() { openerp.base.CompoundDomain = function() { this.__ref = "compound_domain"; this.__domains = []; + this.__eval_context = null; _.each(arguments, function(x) { self.add(x); }); }; openerp.base.CompoundDomain.prototype.add = function(domain) { - if (domain.__ref === "compound_domain") - this.__domains = this.__domains.concat(domain.__domains); - else - this.__domains.push(domain); + this.__domains.push(domain); return this; }; +openerp.base.CompoundDomain.prototype.set_eval_context = function(eval_context) { + this.__eval_context = eval_context; + return this; +}; +openerp.base.CompoundDomain.prototype.get_eval_context = function() { + return this.__eval_context; +}; }; diff --git a/openerpweb/nonliterals.py b/openerpweb/nonliterals.py index 6aedc6bb359..097ba54fe01 100644 --- a/openerpweb/nonliterals.py +++ b/openerpweb/nonliterals.py @@ -8,7 +8,7 @@ import binascii import hashlib import simplejson.encoder -__all__ = ['Domain', 'Context', 'NonLiteralEncoder, non_literal_decoder'] +__all__ = ['Domain', 'Context', 'NonLiteralEncoder, non_literal_decoder', 'CompoundDomain', 'CompoundContext'] #: 48 bits should be sufficient to have almost no chance of collision #: with a million hashes, according to hg@67081329d49a @@ -31,7 +31,8 @@ class NonLiteralEncoder(simplejson.encoder.JSONEncoder): elif isinstance(object, CompoundDomain): return { '__ref': 'compound_domain', - '__domains': object.domains + '__domains': object.domains, + '__eval_context': object.get_eval_context() } elif isinstance(object, CompoundContext): return { @@ -62,13 +63,14 @@ def non_literal_decoder(dct): elif dct["__ref"] == "compound_domain": cdomain = CompoundDomain() for el in dct["__domains"]: - cdomain.domains.append(non_literal_decoder(el)) + cdomain.domains.append(el) + cdomain.set_eval_context(dct.get("__eval_context")) return cdomain elif dct["__ref"] == "compound_context": ccontext = CompoundContext() for el in dct["__contexts"]: - ccontext.contexts.append(non_literal_decoder(el)) - ccontext.set_eval_context(non_literal_decoder(dct.get("__eval_context") or {})) + ccontext.contexts.append(el) + ccontext.set_eval_context(dct.get("__eval_context")) return ccontext return dct @@ -187,6 +189,7 @@ class CompoundDomain(BaseDomain): def __init__(self, *domains): self.domains = [] self.session = None + self.eval_context = None for domain in domains: self.add(domain) @@ -202,6 +205,7 @@ class CompoundDomain(BaseDomain): continue ctx = dict(context or {}) + ctx.update(self.get_eval_context() or {}) ctx['context'] = ctx domain.session = self.session @@ -212,10 +216,12 @@ class CompoundDomain(BaseDomain): self.domains.append(domain) return self -def get_eval_context(context): - if isinstance(context, CompoundContext): - return context.get_eval_context() or {} - return {} + def set_eval_context(self, eval_context): + self.eval_context = eval_context + return self + + def get_eval_context(self): + return self.eval_context class CompoundContext(BaseContext): def __init__(self, *contexts): @@ -246,10 +252,7 @@ class CompoundContext(BaseContext): return final_context def add(self, context): - if isinstance(context, BaseContext): - self.contexts = self.contexts + context.contexts - else: - self.contexts.append(context) + self.contexts.append(context) return self def set_eval_context(self, eval_context):