← Back to team overview

openerp-dev-web team mailing list archive

cleaneval function

 

Sometimes when we try eval string of context or domain may be raised
Exception NameError.
In GTK-client that problem resolved easy:
try:
    eval(string, cnx)
except Exceprion, e:
    logger.getLogger('....').exception(string)
    return {}

In a begining I do same in controllers.main (see
https://bugs.launchpad.net/openerp-web/+bug/816835,
and
http://bazaar.launchpad.net/~openerp-community/openerp-web/qoqenator_lp816835/revision/705
)
But I think that not correct: If only one name in big dictionary is wrong we
return empty dictionary.

I write function clean_eval for better work with wrong names in eval:
http://bazaar.launchpad.net/~openerp-community/openerp-web/qoqenator_cleaneval/revision/706

Example:

string for eval: '{"lang":"US", "action":some_action_exist_in_ctx,
"domain":[("name","like","Correct Name"), ("status","=",status_not_defined),
("parent_id","in",[23,45,wrong_name_of_id])], "foo":bar,
"some_attr":anoter_bad_name}'

context for eval function: {"some_action_exist_in_ctx":"open_window",
"bar":"biz"}

result: {'lang': 'US', 'action': 'open_window', 'domain': [('name', 'like',
'Correct Name'), ('parent_id', 'in', [23, 45])], 'foo': 'biz'}

You can see: pair key:value with wrong name removed from dict, wrong name
removed from list and domain tuple contains wrong name remove from domain
list.

Follow ups