[ADD] evaluation of search contexts and domains, hook ViewManager to the dataset in order to perform the correct search.
I'm pretty sure there's a race condition somewhere in there, in the initial loading of the whole mess I bet we can have the auto_search triggering before the list controller is done loading... We probably need some deferred (one for each searchable view in the manager + one for the searchview itself) and a final one waiting on them all (I don't think jquery's deferred can do that built-in) before launching the auto_search bzr revid: xmo@openerp.com-20110325123252-fjrgj4aicac3fo3b
This commit is contained in:
parent
9760d629a5
commit
632d93afa7
|
@ -113,6 +113,14 @@ class Session(openerpweb.Controller):
|
|||
return concat
|
||||
js.exposed = True
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def eval_domain_and_context(self, req, contexts, domains):
|
||||
context = req.session.eval_contexts(contexts)
|
||||
domain = req.session.eval_domains(domains, context)
|
||||
return {
|
||||
'context': context,
|
||||
'domain': domain
|
||||
}
|
||||
|
||||
class Menu(openerpweb.Controller):
|
||||
_cp_path = "/base/menu"
|
||||
|
|
|
@ -116,8 +116,16 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
|||
on_edit: function() {
|
||||
},
|
||||
do_search: function (domains, contexts) {
|
||||
console.log('domains', domains);
|
||||
console.log('contexts', contexts);
|
||||
var self = this;
|
||||
this.rpc('/base/session/eval_domain_and_context', {
|
||||
domains: domains,
|
||||
contexts: contexts
|
||||
}, function (results) {
|
||||
self.dataset.set({
|
||||
context: results.context,
|
||||
domain: results.domain
|
||||
}).fetch(0, self.action.limit);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -881,10 +889,10 @@ openerp.base.FormView = openerp.base.Controller.extend({
|
|||
}
|
||||
// bind to all wdigets that have onchange ??
|
||||
|
||||
this.dataset.on_fetch.add(this.on_record_loaded);
|
||||
this.dataset.on_active_id.add(this.on_record_loaded);
|
||||
},
|
||||
on_record_loaded: function(records) {
|
||||
this.datarecord = records[0];
|
||||
on_record_loaded: function(record) {
|
||||
this.datarecord = record;
|
||||
for (var f in this.fields) {
|
||||
this.fields[f].set_value(this.datarecord.values[f]);
|
||||
}
|
||||
|
|
|
@ -122,25 +122,58 @@ class OpenERPSession(object):
|
|||
**self.context
|
||||
)
|
||||
|
||||
def eval_context(self, context_string, context=None):
|
||||
def eval_context(self, context_string, context=None, use_base=True):
|
||||
""" Evaluates the provided context_string in the context (haha) of
|
||||
the context.
|
||||
|
||||
:param str context_string: a context to evaluate, if not a string,
|
||||
will be returned as-is
|
||||
:param dict context: the context to use in the evaluation, if any.
|
||||
Will be merged with a default context and
|
||||
the session context.
|
||||
:param bool use_base: whether the base eval context (combination
|
||||
of the default context and the session
|
||||
context) should be merged to the provided
|
||||
context (or used alone)
|
||||
:returns: the evaluated context
|
||||
:rtype: dict
|
||||
"""
|
||||
if not isinstance(context_string, basestring):
|
||||
return context_string
|
||||
|
||||
return eval(context_string, dict(
|
||||
|
||||
ctx = {}
|
||||
if use_base:
|
||||
ctx.update(self.base_eval_context)
|
||||
if context:
|
||||
ctx.update(context)
|
||||
|
||||
return eval(context_string, ctx)
|
||||
|
||||
def eval_contexts(self, contexts, context=None):
|
||||
""" Evaluates a sequence of contexts to build a single final result
|
||||
|
||||
:param list contexts: a list of string or dict contexts
|
||||
:param dict context: a base context, if needed
|
||||
:returns: the final combination of all provided contexts
|
||||
:rtype: dict
|
||||
"""
|
||||
# This is the context we use to evaluate stuff
|
||||
current_context = dict(
|
||||
self.base_eval_context,
|
||||
**(context or {})))
|
||||
def eval_domain(self, domain_string, context=None):
|
||||
**(context or {}))
|
||||
# this is our result, it should not contain the values
|
||||
# of the base context above
|
||||
final_context = {}
|
||||
for ctx in contexts:
|
||||
# evaluate the current context in the sequence, merge it into
|
||||
# the result
|
||||
final_context.update(
|
||||
self.eval_context(
|
||||
ctx, current_context, use_base=False))
|
||||
# update the current evaluation context so that future
|
||||
# evaluations can use the results we just gathered
|
||||
current_context.update(final_context)
|
||||
return final_context
|
||||
|
||||
def eval_domain(self, domain_string, context=None, use_base=True):
|
||||
""" Evaluates the provided domain_string using the provided context
|
||||
(merged with the session's evaluation context)
|
||||
|
||||
|
@ -148,15 +181,45 @@ class OpenERPSession(object):
|
|||
|
||||
If not a string, is returned as-is
|
||||
:param dict context: the context to use in the evaluation, if any.
|
||||
:param bool use_base: whether the base eval context (combination
|
||||
of the default context and the session
|
||||
context) should be used
|
||||
:returns: the evaluated domain
|
||||
:rtype: list
|
||||
"""
|
||||
if not isinstance(domain_string, basestring):
|
||||
return domain_string
|
||||
|
||||
return eval(domain_string, dict(
|
||||
ctx = {}
|
||||
if use_base:
|
||||
ctx.update(self.base_eval_context)
|
||||
if context:
|
||||
ctx.update(context)
|
||||
|
||||
return eval(domain_string, ctx)
|
||||
|
||||
def eval_domains(self, domains, context=None):
|
||||
""" Evaluates and concatenates the provided domains using the
|
||||
provided context for all of them.
|
||||
|
||||
Returns the final, concatenated result.
|
||||
|
||||
:param list domains: a list of string or list domains
|
||||
:param dict context: the context in which the domains
|
||||
should be evaluated (if evaluations need
|
||||
to happen)
|
||||
:returns: the final combination of all domains in the sequence
|
||||
:rtype: list
|
||||
"""
|
||||
ctx = dict(
|
||||
self.base_eval_context,
|
||||
**(context or {})))
|
||||
**(context or {}))
|
||||
|
||||
final_domain = []
|
||||
for domain in domains:
|
||||
final_domain.extend(
|
||||
self.eval_domain(domain, ctx))
|
||||
return final_domain
|
||||
|
||||
#----------------------------------------------------------
|
||||
# OpenERP Web RequestHandler
|
||||
|
|
Loading…
Reference in New Issue