[REM] server-side eval_domain_and_context
bzr revid: xmo@openerp.com-20121123113932-siz0u2vp2u7z6wk2
This commit is contained in:
parent
49bd834725
commit
709f2506ff
|
@ -919,59 +919,6 @@ class Session(openerpweb.Controller):
|
|||
# return all installed modules. Web client is smart enough to not load a module twice
|
||||
return module_installed(req)
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def eval_domain_and_context(self, req, contexts, domains,
|
||||
group_by_seq=None):
|
||||
""" Evaluates sequences of domains and contexts, composing them into
|
||||
a single context, domain or group_by sequence.
|
||||
|
||||
:param list contexts: list of contexts to merge together. Contexts are
|
||||
evaluated in sequence, all previous contexts
|
||||
are part of their own evaluation context
|
||||
(starting at the session context).
|
||||
:param list domains: list of domains to merge together. Domains are
|
||||
evaluated in sequence and appended to one another
|
||||
(implicit AND), their evaluation domain is the
|
||||
result of merging all contexts.
|
||||
:param list group_by_seq: list of domains (which may be in a different
|
||||
order than the ``contexts`` parameter),
|
||||
evaluated in sequence, their ``'group_by'``
|
||||
key is extracted if they have one.
|
||||
:returns:
|
||||
a 3-dict of:
|
||||
|
||||
context (``dict``)
|
||||
the global context created by merging all of
|
||||
``contexts``
|
||||
|
||||
domain (``list``)
|
||||
the concatenation of all domains
|
||||
|
||||
group_by (``list``)
|
||||
a list of fields to group by, potentially empty (in which case
|
||||
no group by should be performed)
|
||||
"""
|
||||
context, domain = eval_context_and_domain(req.session,
|
||||
nonliterals.CompoundContext(*(contexts or [])),
|
||||
nonliterals.CompoundDomain(*(domains or [])))
|
||||
|
||||
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
|
||||
def save_session_action(self, req, the_action):
|
||||
"""
|
||||
|
|
|
@ -257,16 +257,17 @@ method you want to call) and a mapping of attributes to values (applied
|
|||
as keyword arguments on the Python method [#]_). This function fetches
|
||||
the return value of the Python methods, converted to JSON.
|
||||
|
||||
For instance, to call the ``eval_domain_and_context`` of the
|
||||
:class:`~web.controllers.main.Session` controller:
|
||||
For instance, to call the ``resequence`` of the
|
||||
:class:`~web.controllers.main.DataSet` controller:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
openerp.connection.rpc('/web/session/eval_domain_and_context', {
|
||||
domains: ds,
|
||||
contexts: cs
|
||||
openerp.connection.rpc('/web/dataset/resequence', {
|
||||
model: some_model,
|
||||
ids: array_of_ids,
|
||||
offset: 42
|
||||
}).then(function (result) {
|
||||
// handle result
|
||||
// resequenced on server
|
||||
});
|
||||
|
||||
.. [#] with a small twist: SQLAlchemy's ``orm.query.Query.group_by``
|
||||
|
|
|
@ -965,15 +965,8 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
|
|||
var deferred = $.Deferred();
|
||||
if (! options.shadow)
|
||||
this.trigger('request', url, payload);
|
||||
var request;
|
||||
// if (url.url === '/web/session/eval_domain_and_context') {
|
||||
// // intercept eval_domain_and_context
|
||||
// request = instance.web.pyeval.eval_domains_and_contexts(
|
||||
// params)
|
||||
// } else {
|
||||
request = this.rpc_function(url, payload);
|
||||
// }
|
||||
request.then(
|
||||
|
||||
this.rpc_function(url, payload).then(
|
||||
function (response, textStatus, jqXHR) {
|
||||
if (! options.shadow)
|
||||
self.trigger('response', response);
|
||||
|
|
|
@ -739,13 +739,13 @@ openerp.web.pyeval = function (instance) {
|
|||
instance.web.pyeval.eval_domains_and_contexts = function (source) {
|
||||
return new $.Deferred(function (d) {setTimeout(function () {
|
||||
try {
|
||||
var contexts = ([instance.session.context] || []).concat(source.contexts);
|
||||
var contexts = ([instance.session.user_context] || []).concat(source.contexts);
|
||||
// see Session.eval_context in Python
|
||||
d.resolve({result: {
|
||||
d.resolve({
|
||||
context: instance.web.pyeval.eval('contexts', contexts),
|
||||
domain: instance.web.pyeval.eval('domains', source.domains),
|
||||
group_by: instance.web.pyeval.eval('groupbys', source.group_by_seq)
|
||||
}}, 'success', {});
|
||||
group_by: instance.web.pyeval.eval('groupbys', source.group_by_seq || [])
|
||||
});
|
||||
} catch (e) {
|
||||
d.resolve({ error: {
|
||||
code: 400,
|
||||
|
|
|
@ -1614,7 +1614,7 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({
|
|||
var set_as_default = this.$('#oe_searchview_custom_default').prop('checked');
|
||||
|
||||
var search = this.view.build_search_data();
|
||||
this.rpc('/web/session/eval_domain_and_context', {
|
||||
instance.web.pyeval.eval_domains_and_contexts({
|
||||
domains: search.domains,
|
||||
contexts: search.contexts,
|
||||
group_by_seq: search.groupbys || []
|
||||
|
|
|
@ -4588,7 +4588,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
|
|||
var self = this;
|
||||
this.init_dataset();
|
||||
if (this.options.initial_view == "search") {
|
||||
self.rpc('/web/session/eval_domain_and_context', {
|
||||
instance.web.pyeval.eval_domains_and_contexts({
|
||||
domains: [],
|
||||
contexts: [this.context]
|
||||
}).done(function (results) {
|
||||
|
@ -4659,7 +4659,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
|
|||
},
|
||||
do_search: function(domains, contexts, groupbys) {
|
||||
var self = this;
|
||||
this.rpc('/web/session/eval_domain_and_context', {
|
||||
instance.web.pyeval.eval_domains_and_contexts({
|
||||
domains: domains || [],
|
||||
contexts: contexts || [],
|
||||
group_by_seq: groupbys || []
|
||||
|
|
|
@ -236,7 +236,7 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
|
|||
if (action.context) {
|
||||
c.add(action.context);
|
||||
}
|
||||
return self.rpc('/web/session/eval_domain_and_context', {
|
||||
return instance.web.pyeval.eval_domains_and_contexts({
|
||||
contexts: [c], domains: []
|
||||
}).then(function (res) {
|
||||
action.context = res.context;
|
||||
|
|
|
@ -396,7 +396,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
|
|||
ir_actions_report_xml: function(action, options) {
|
||||
var self = this;
|
||||
instance.web.blockUI();
|
||||
self.rpc("/web/session/eval_domain_and_context", {
|
||||
instance.web.pyeval.eval_domains_and_contexts({
|
||||
contexts: [action.context],
|
||||
domains: []
|
||||
}).done(function(res) {
|
||||
|
@ -667,7 +667,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
|||
var self = this,
|
||||
controller = this.views[this.active_view].controller,
|
||||
action_context = this.action.context || {};
|
||||
this.rpc('/web/session/eval_domain_and_context', {
|
||||
instance.web.pyeval.eval_domains_and_contexts({
|
||||
domains: [this.action.domain || []].concat(domains || []),
|
||||
contexts: [action_context].concat(contexts || []),
|
||||
group_by_seq: groupbys || []
|
||||
|
@ -1227,7 +1227,7 @@ instance.web.View = instance.web.Widget.extend({
|
|||
});
|
||||
}
|
||||
ncontext.add(action.context || {});
|
||||
return self.rpc('/web/session/eval_domain_and_context', {
|
||||
return instance.web.pyeval.eval_domains_and_contexts({
|
||||
contexts: [ncontext],
|
||||
domains: []
|
||||
}).then(function (results) {
|
||||
|
|
|
@ -247,8 +247,13 @@ openerp.testing.section('eval.edc', {
|
|||
dependencies: ['web.data'],
|
||||
rpc: 'rpc',
|
||||
setup: function (instance) {
|
||||
instance.session.user_context = {
|
||||
lang: 'en_US',
|
||||
tz: false,
|
||||
uid: 1
|
||||
};
|
||||
instance.edc = function (domains, contexts) {
|
||||
return this.session.rpc('/web/session/eval_domain_and_context', {
|
||||
return instance.web.pyeval.eval_domains_and_contexts({
|
||||
contexts: contexts || [],
|
||||
domains: domains || []
|
||||
});
|
||||
|
@ -382,9 +387,14 @@ openerp.testing.section('eval.edc.nonliterals', {
|
|||
dependencies: ['web.data'],
|
||||
rpc: 'rpc',
|
||||
setup: function (instance) {
|
||||
instance.session.user_context = {
|
||||
lang: 'en_US',
|
||||
tz: false,
|
||||
uid: 1
|
||||
};
|
||||
_.extend(instance, {
|
||||
edc: function (domains, contexts) {
|
||||
return this.session.rpc('/web/session/eval_domain_and_context', {
|
||||
return instance.web.pyeval.eval_domains_and_contexts({
|
||||
contexts: contexts || [],
|
||||
domains: domains || []
|
||||
});
|
||||
|
@ -398,7 +408,7 @@ openerp.testing.section('eval.edc.nonliterals', {
|
|||
});
|
||||
}
|
||||
}, function (test) {
|
||||
test('domain with time', {asserts: 2}, function (instance) {
|
||||
test('domain with time', {asserts: 1}, function (instance) {
|
||||
return instance.load_domain(0).then(function (d) {
|
||||
strictEqual(d.__ref, 'domain');
|
||||
return instance.edc([
|
||||
|
@ -409,7 +419,7 @@ openerp.testing.section('eval.edc.nonliterals', {
|
|||
},
|
||||
d,
|
||||
[['user_id', '=', 1]]
|
||||
])
|
||||
]);
|
||||
}).then(function (result) {
|
||||
var d = new Date();
|
||||
var today = _.str.sprintf("%04d-%02d-%02d",
|
||||
|
|
Loading…
Reference in New Issue