[imp] refactoring to allow correct context handling in clean_action
bzr revid: nicolas.vanhoren@openerp.com-20110825170410-omj3wrugqmslck8w
This commit is contained in:
parent
9225fe4074
commit
fc766e16fe
|
@ -423,25 +423,25 @@ def eval_context_and_domain(session, context, domain=None):
|
||||||
|
|
||||||
return e_context, e_domain
|
return e_context, e_domain
|
||||||
|
|
||||||
def load_actions_from_ir_values(req, key, key2, models, meta, context):
|
def load_actions_from_ir_values(req, key, key2, models, meta):
|
||||||
|
context = req.session.eval_context(req.context)
|
||||||
Values = req.session.model('ir.values')
|
Values = req.session.model('ir.values')
|
||||||
actions = Values.get(key, key2, models, meta, context)
|
actions = Values.get(key, key2, models, meta, context)
|
||||||
|
|
||||||
return [(id, name, clean_action(action, req.session, context=context))
|
return [(id, name, clean_action(req, action))
|
||||||
for id, name, action in actions]
|
for id, name, action in actions]
|
||||||
|
|
||||||
def clean_action(action, session, context=None):
|
def clean_action(req, action):
|
||||||
|
context = req.session.eval_context(req.context)
|
||||||
|
eval_ctx = req.session.evaluation_context(context)
|
||||||
action.setdefault('flags', {})
|
action.setdefault('flags', {})
|
||||||
if action['type'] != 'ir.actions.act_window':
|
|
||||||
return action
|
|
||||||
# values come from the server, we can just eval them
|
# values come from the server, we can just eval them
|
||||||
if isinstance(action.get('context'), basestring):
|
if isinstance(action.get('context'), basestring):
|
||||||
localvars = session.evaluation_context(context=context)
|
action['context'] = eval( action['context'], eval_ctx ) or {}
|
||||||
action['context'] = eval( action['context'], localvars ) or {}
|
|
||||||
|
|
||||||
if isinstance(action.get('domain'), basestring):
|
if isinstance(action.get('domain'), basestring):
|
||||||
localvars = session.evaluation_context( action.get('context', {}))
|
action['domain'] = eval( action['domain'], eval_ctx ) or []
|
||||||
action['domain'] = eval( action['domain'], localvars ) or []
|
|
||||||
|
|
||||||
return fix_view_modes(action)
|
return fix_view_modes(action)
|
||||||
|
|
||||||
|
@ -559,8 +559,7 @@ class Menu(openerpweb.Controller):
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def action(self, req, menu_id):
|
def action(self, req, menu_id):
|
||||||
actions = load_actions_from_ir_values(req,'action', 'tree_but_open',
|
actions = load_actions_from_ir_values(req,'action', 'tree_but_open',
|
||||||
[('ir.ui.menu', menu_id)], False,
|
[('ir.ui.menu', menu_id)], False)
|
||||||
req.session.eval_context(req.context))
|
|
||||||
return {"action": actions}
|
return {"action": actions}
|
||||||
|
|
||||||
class DataSet(openerpweb.Controller):
|
class DataSet(openerpweb.Controller):
|
||||||
|
@ -696,7 +695,7 @@ class DataSet(openerpweb.Controller):
|
||||||
def call_button(self, req, model, method, args, domain_id=None, context_id=None):
|
def call_button(self, req, model, method, args, domain_id=None, context_id=None):
|
||||||
action = self.call_common(req, model, method, args, domain_id, context_id)
|
action = self.call_common(req, model, method, args, domain_id, context_id)
|
||||||
if isinstance(action, dict) and action.get('type') != '':
|
if isinstance(action, dict) and action.get('type') != '':
|
||||||
return {'result': clean_action(action, req.session)}
|
return {'result': clean_action(req, action)}
|
||||||
return {'result': False}
|
return {'result': False}
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
|
@ -1040,13 +1039,13 @@ class Action(openerpweb.Controller):
|
||||||
action = req.session.model(action_type[0]['type']).read([action_id], False,
|
action = req.session.model(action_type[0]['type']).read([action_id], False,
|
||||||
context)
|
context)
|
||||||
if action:
|
if action:
|
||||||
value = clean_action(action[0], req.session)
|
value = clean_action(req, action[0])
|
||||||
return {'result': value}
|
return {'result': value}
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def run(self, req, action_id):
|
def run(self, req, action_id):
|
||||||
return clean_action(req.session.model('ir.actions.server').run(
|
return clean_action(req, req.session.model('ir.actions.server').run(
|
||||||
[action_id], req.session.eval_context(req.context)), req.session)
|
[action_id], req.session.eval_context(req.context)))
|
||||||
|
|
||||||
class TreeView(View):
|
class TreeView(View):
|
||||||
_cp_path = "/base/treeview"
|
_cp_path = "/base/treeview"
|
||||||
|
@ -1059,7 +1058,7 @@ class TreeView(View):
|
||||||
def action(self, req, model, id):
|
def action(self, req, model, id):
|
||||||
return load_actions_from_ir_values(
|
return load_actions_from_ir_values(
|
||||||
req,'action', 'tree_but_open',[(model, id)],
|
req,'action', 'tree_but_open',[(model, id)],
|
||||||
False, req.session.eval_context(req.context))
|
False)
|
||||||
|
|
||||||
def export_csv(fields, result):
|
def export_csv(fields, result):
|
||||||
fp = StringIO()
|
fp = StringIO()
|
||||||
|
|
|
@ -1334,6 +1334,11 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
self.set_value(self.value[0]);
|
self.set_value(self.value[0]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
_.each(_.range(self.related_entries.length), function(i) {
|
||||||
|
bindings[self.cm_id + "_related_" + i] = function() {
|
||||||
|
self.open_related(self.related_entries[i]);
|
||||||
|
};
|
||||||
|
});
|
||||||
var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'leftClickToo': true,
|
var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'leftClickToo': true,
|
||||||
bindings: bindings, itemStyle: {"color": ""},
|
bindings: bindings, itemStyle: {"color": ""},
|
||||||
onContextMenu: function() {
|
onContextMenu: function() {
|
||||||
|
@ -1544,6 +1549,22 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
if (this.value === null) {
|
if (this.value === null) {
|
||||||
this.invalid = this.required;
|
this.invalid = this.required;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
open_related: function(related) {
|
||||||
|
var self = this;
|
||||||
|
if (!self.value)
|
||||||
|
return;
|
||||||
|
self.rpc("/base/action/load", {
|
||||||
|
action_id: related[2].id,
|
||||||
|
context: {
|
||||||
|
active_id: self.value[0],
|
||||||
|
active_ids: self.value[1],
|
||||||
|
active_model: self.field.relation
|
||||||
|
}
|
||||||
|
}, function(result) {
|
||||||
|
//TODO niv
|
||||||
|
debugger;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue