[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:
parent
858f61c6be
commit
e975b4ac1e
|
@ -170,25 +170,7 @@ class Session(openerpweb.Controller):
|
||||||
a list of fields to group by, potentially empty (in which case
|
a list of fields to group by, potentially empty (in which case
|
||||||
no group by should be performed)
|
no group by should be performed)
|
||||||
"""
|
"""
|
||||||
context = req.session.eval_contexts(contexts)
|
return _eval_domain_and_context(req, contexts, domains, group_by_seq)
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def save_session_action(self, req, the_action):
|
def save_session_action(self, req, the_action):
|
||||||
|
@ -230,6 +212,26 @@ class Session(openerpweb.Controller):
|
||||||
return None
|
return None
|
||||||
return saved_actions["actions"].get(key)
|
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):
|
def load_actions_from_ir_values(req, key, key2, models, meta, context):
|
||||||
Values = req.session.model('ir.values')
|
Values = req.session.model('ir.values')
|
||||||
|
@ -434,7 +436,15 @@ class DataSet(openerpweb.Controller):
|
||||||
return Model.unlink(ids)
|
return Model.unlink(ids)
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@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)
|
m = req.session.model(model)
|
||||||
r = getattr(m, method)(*args)
|
r = getattr(m, method)(*args)
|
||||||
return {'result': r}
|
return {'result': r}
|
||||||
|
|
|
@ -320,13 +320,22 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
||||||
args: args || []
|
args: args || []
|
||||||
}, callback, error_callback);
|
}, 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:
|
* Arguments:
|
||||||
* name='', args=[], operator='ilike', context=None, limit=100
|
* name='', args=[], operator='ilike', context=None, limit=100
|
||||||
*/
|
*/
|
||||||
name_search: function (args, callback, error_callback) {
|
name_search: function (args, callback, error_callback) {
|
||||||
return this.call('name_search',
|
return this.call_and_eval('name_search',
|
||||||
args,
|
args, 1, 3,
|
||||||
callback, error_callback);
|
callback, error_callback);
|
||||||
},
|
},
|
||||||
exec_workflow: function (id, signal, callback) {
|
exec_workflow: function (id, signal, callback) {
|
||||||
|
@ -443,6 +452,7 @@ openerp.base.CompoundContext = function(source_context) {
|
||||||
};
|
};
|
||||||
openerp.base.CompoundContext.prototype.add = function(context) {
|
openerp.base.CompoundContext.prototype.add = function(context) {
|
||||||
this.__contexts.push(context);
|
this.__contexts.push(context);
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
openerp.base.CompoundDomain = function(source_domain) {
|
openerp.base.CompoundDomain = function(source_domain) {
|
||||||
|
@ -457,6 +467,7 @@ openerp.base.CompoundDomain = function(source_domain) {
|
||||||
};
|
};
|
||||||
openerp.base.CompoundDomain.prototype.add = function(domain) {
|
openerp.base.CompoundDomain.prototype.add = function(domain) {
|
||||||
this.__domains.push(domain);
|
this.__domains.push(domain);
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1021,7 +1021,8 @@ var build_relation_context = function(relation_field) {
|
||||||
var action = relation_field.view.view_manager.action || {};
|
var action = relation_field.view.view_manager.action || {};
|
||||||
var a_context = action.context || {};
|
var a_context = action.context || {};
|
||||||
var f_context = relation_field.field.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({
|
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) {
|
select_element: function(model, options, domain, context) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.domain = domain;
|
this.domain = domain || [];
|
||||||
this.context = context;
|
this.context = context || {};
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
this.initial_ids = this.options.initial_ids;
|
this.initial_ids = this.options.initial_ids;
|
||||||
jQuery(this.render()).dialog({title: '',
|
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.view_form = new openerp.base.FormView(null, this.session,
|
||||||
this.element_id + "_view_form", this.dataset, false);
|
this.element_id + "_view_form", this.dataset, false);
|
||||||
if (this.options.alternative_form_view) {
|
if (this.options.alternative_form_view) {
|
||||||
debugger;
|
|
||||||
this.view_form.set_embedded_view(this.options.alternative_form_view);
|
this.view_form.set_embedded_view(this.options.alternative_form_view);
|
||||||
}
|
}
|
||||||
this.view_form.start();
|
this.view_form.start();
|
||||||
|
|
|
@ -167,7 +167,7 @@ class CompoundDomain:
|
||||||
def evaluate(self, context=None):
|
def evaluate(self, context=None):
|
||||||
final_domain = []
|
final_domain = []
|
||||||
for domain in self.domains:
|
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",
|
raise TypeError("Domain %r is not a list or a nonliteral Domain",
|
||||||
domain)
|
domain)
|
||||||
|
|
||||||
|
@ -180,6 +180,7 @@ class CompoundDomain:
|
||||||
|
|
||||||
domain.session = self.session
|
domain.session = self.session
|
||||||
domain.extend(domain.evaluate(ctx))
|
domain.extend(domain.evaluate(ctx))
|
||||||
|
return final_domain
|
||||||
|
|
||||||
def add(self, domain):
|
def add(self, domain):
|
||||||
self.domains.append(domain)
|
self.domains.append(domain)
|
||||||
|
@ -191,9 +192,10 @@ class CompoundContext:
|
||||||
self.session = None
|
self.session = None
|
||||||
|
|
||||||
def evaluate(self, context=None):
|
def evaluate(self, context=None):
|
||||||
final_context = dict(context or {})
|
ctx = dict(context or {})
|
||||||
|
final_context = {}
|
||||||
for context_to_eval in self.contexts:
|
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",
|
raise TypeError("Context %r is not a dict or a nonliteral Context",
|
||||||
context_to_eval)
|
context_to_eval)
|
||||||
|
|
||||||
|
@ -201,11 +203,12 @@ class CompoundContext:
|
||||||
final_context.update(context_to_eval)
|
final_context.update(context_to_eval)
|
||||||
break
|
break
|
||||||
|
|
||||||
ctx = dict(final_context)
|
ctx.update(final_context)
|
||||||
ctx["context"] = ctx
|
ctx["context"] = ctx
|
||||||
|
|
||||||
context_to_eval.session = self.session
|
context_to_eval.session = self.session
|
||||||
final_context.update(context_to_eval.evaluate(ctx))
|
final_context.update(context_to_eval.evaluate(ctx))
|
||||||
|
return final_context
|
||||||
|
|
||||||
def add(self, context):
|
def add(self, context):
|
||||||
self.contexts.append(context)
|
self.contexts.append(context)
|
||||||
|
|
Loading…
Reference in New Issue