[imp] added compound context and compound domain and implemented correctly context & domain handling in m2o

bzr revid: nicolas.vanhoren@openerp.com-20110617120834-c616130ueklb3rxs
This commit is contained in:
niv-openerp 2011-06-17 14:08:34 +02:00
parent 858f61c6be
commit e975b4ac1e
4 changed files with 54 additions and 30 deletions

View File

@ -170,25 +170,7 @@ class Session(openerpweb.Controller):
a list of fields to group by, potentially empty (in which case
no group by should be performed)
"""
context = req.session.eval_contexts(contexts)
domain = req.session.eval_domains(domains, context)
group_by_sequence = []
for candidate in (group_by_seq or []):
ctx = req.session.eval_context(candidate, context)
group_by = ctx.get('group_by')
if not group_by:
continue
elif isinstance(group_by, basestring):
group_by_sequence.append(group_by)
else:
group_by_sequence.extend(group_by)
return {
'context': context,
'domain': domain,
'group_by': group_by_sequence
}
return _eval_domain_and_context(req, contexts, domains, group_by_seq)
@openerpweb.jsonrequest
def save_session_action(self, req, the_action):
@ -230,6 +212,26 @@ class Session(openerpweb.Controller):
return None
return saved_actions["actions"].get(key)
def _eval_domain_and_context(req, contexts, domains, group_by_seq=None):
context = req.session.eval_contexts(contexts)
domain = req.session.eval_domains(domains, context)
group_by_sequence = []
for candidate in (group_by_seq or []):
ctx = req.session.eval_context(candidate, context)
group_by = ctx.get('group_by')
if not group_by:
continue
elif isinstance(group_by, basestring):
group_by_sequence.append(group_by)
else:
group_by_sequence.extend(group_by)
return {
'context': context,
'domain': domain,
'group_by': group_by_sequence
}
def load_actions_from_ir_values(req, key, key2, models, meta, context):
Values = req.session.model('ir.values')
@ -434,7 +436,15 @@ class DataSet(openerpweb.Controller):
return Model.unlink(ids)
@openerpweb.jsonrequest
def call(self, req, model, method, args):
def call(self, req, model, method, args, domain_id=None, context_id=None):
domain = args[domain_id] if domain_id and len(args) - 1 >= domain_id else []
context = args[context_id] if context_id and len(args) - 1 >= context_id else {}
res = _eval_domain_and_context(req, [context], [domain]);
if(domain_id and len(args) - 1 >= domain_id):
args[context_id] = res["context"]
if(context_id and len(args) - 1 >= context_id):
args[domain_id] = res["domain"]
m = req.session.model(model)
r = getattr(m, method)(*args)
return {'result': r}

View File

@ -320,13 +320,22 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
args: args || []
}, callback, error_callback);
},
call_and_eval: function (method, args, domain_id, context_id, callback, error_callback) {
return this.rpc('/base/dataset/call', {
model: this.model,
method: method,
domain_id: domain_id || null,
context_id: context_id || null,
args: args || []
}, callback, error_callback);
},
/**
* Arguments:
* name='', args=[], operator='ilike', context=None, limit=100
*/
name_search: function (args, callback, error_callback) {
return this.call('name_search',
args,
return this.call_and_eval('name_search',
args, 1, 3,
callback, error_callback);
},
exec_workflow: function (id, signal, callback) {
@ -443,6 +452,7 @@ openerp.base.CompoundContext = function(source_context) {
};
openerp.base.CompoundContext.prototype.add = function(context) {
this.__contexts.push(context);
return this;
};
openerp.base.CompoundDomain = function(source_domain) {
@ -457,6 +467,7 @@ openerp.base.CompoundDomain = function(source_domain) {
};
openerp.base.CompoundDomain.prototype.add = function(domain) {
this.__domains.push(domain);
return this;
};
};

View File

@ -1021,7 +1021,8 @@ var build_relation_context = function(relation_field) {
var action = relation_field.view.view_manager.action || {};
var a_context = action.context || {};
var f_context = relation_field.field.context || {};
return $.extend({}, a_context, f_context);
var ctx = new openerp.base.CompoundContext(a_context).add(f_context);
return ctx;
}
openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
@ -1419,8 +1420,8 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
*/
select_element: function(model, options, domain, context) {
this.model = model;
this.domain = domain;
this.context = context;
this.domain = domain || [];
this.context = context || {};
this.options = options || {};
this.initial_ids = this.options.initial_ids;
jQuery(this.render()).dialog({title: '',
@ -1503,7 +1504,6 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
this.view_form = new openerp.base.FormView(null, this.session,
this.element_id + "_view_form", this.dataset, false);
if (this.options.alternative_form_view) {
debugger;
this.view_form.set_embedded_view(this.options.alternative_form_view);
}
this.view_form.start();

View File

@ -167,7 +167,7 @@ class CompoundDomain:
def evaluate(self, context=None):
final_domain = []
for domain in self.domains:
if not isinstance(domain, (list, nonliterals.Domain, nonliterals.CompoundDomain)):
if not isinstance(domain, (list, Domain, CompoundDomain)):
raise TypeError("Domain %r is not a list or a nonliteral Domain",
domain)
@ -180,6 +180,7 @@ class CompoundDomain:
domain.session = self.session
domain.extend(domain.evaluate(ctx))
return final_domain
def add(self, domain):
self.domains.append(domain)
@ -191,9 +192,10 @@ class CompoundContext:
self.session = None
def evaluate(self, context=None):
final_context = dict(context or {})
ctx = dict(context or {})
final_context = {}
for context_to_eval in self.contexts:
if not isinstance(context_to_eval, (dict, nonliterals.Context, nonliterals.CompoundContext)):
if not isinstance(context_to_eval, (dict, Context, CompoundContext)):
raise TypeError("Context %r is not a dict or a nonliteral Context",
context_to_eval)
@ -201,11 +203,12 @@ class CompoundContext:
final_context.update(context_to_eval)
break
ctx = dict(final_context)
ctx.update(final_context)
ctx["context"] = ctx
context_to_eval.session = self.session
final_context.update(context_to_eval.evaluate(ctx))
return final_context
def add(self, context):
self.contexts.append(context)