[ADD] handling of own values on fields (e.g. self, values which are used to evaluate the field's context and domain, but not any other field's)
Also fix bugs in fields_view_get: didn't evaluate filter_domain to a nonliteral Domain (or a literal domain dict) bzr revid: xmo@openerp.com-20110329090941-av5ymojubq23yjim
This commit is contained in:
parent
e549c9f7cb
commit
c3d74fe290
|
@ -368,6 +368,28 @@ class View(openerpweb.Controller):
|
|||
self.parse_domains_and_contexts(elem, session)
|
||||
return root
|
||||
|
||||
def parse_domain(self, elem, attr_name, session):
|
||||
""" Parses an attribute of the provided name as a domain, transforms it
|
||||
to either a literal domain or a :class:`openerpweb.nonliterals.Domain`
|
||||
|
||||
:param elem: the node being parsed
|
||||
:type param: xml.etree.ElementTree.Element
|
||||
:param str attr_name: the name of the attribute which should be parsed
|
||||
:param session: Current OpenERP session
|
||||
:type session: openerpweb.openerpweb.OpenERPSession
|
||||
"""
|
||||
domain = elem.get(attr_name)
|
||||
if domain:
|
||||
try:
|
||||
elem.set(
|
||||
attr_name,
|
||||
openerpweb.ast.literal_eval(
|
||||
domain))
|
||||
except ValueError:
|
||||
# not a literal
|
||||
elem.set(attr_name,
|
||||
openerpweb.nonliterals.Domain(session, domain))
|
||||
|
||||
def parse_domains_and_contexts(self, elem, session):
|
||||
""" Converts domains and contexts from the view into Python objects,
|
||||
either literals if they can be parsed by literal_eval or a special
|
||||
|
@ -379,17 +401,8 @@ class View(openerpweb.Controller):
|
|||
non-literal objects
|
||||
:type session: openerpweb.openerpweb.OpenERPSession
|
||||
"""
|
||||
domain = elem.get('domain')
|
||||
if domain:
|
||||
try:
|
||||
elem.set(
|
||||
'domain',
|
||||
openerpweb.ast.literal_eval(
|
||||
domain))
|
||||
except ValueError:
|
||||
# not a literal
|
||||
elem.set('domain',
|
||||
openerpweb.nonliterals.Domain(session, domain))
|
||||
self.parse_domain(elem, 'domain', session)
|
||||
self.parse_domain(elem, 'filter_domain', session)
|
||||
context_string = elem.get('context')
|
||||
if context_string:
|
||||
try:
|
||||
|
|
|
@ -783,10 +783,13 @@ openerp.base.search.Field = openerp.base.search.Input.extend({
|
|||
// A field needs a value to be "active", and a context to send when
|
||||
// active
|
||||
var has_value = (val !== null && val !== '');
|
||||
if (!(has_value && this.attrs.context)) {
|
||||
var context = this.attrs.context;
|
||||
if (!(has_value && context)) {
|
||||
return;
|
||||
}
|
||||
return this.attrs.context;
|
||||
return _.extend(
|
||||
{}, context,
|
||||
{own_values: {self: val}});
|
||||
},
|
||||
get_domain: function () {
|
||||
var val = this.get_value();
|
||||
|
@ -796,14 +799,17 @@ openerp.base.search.Field = openerp.base.search.Input.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this.attrs['filter_domain']) {
|
||||
var domain = this.attrs['filter_domain'];
|
||||
if (!domain) {
|
||||
return [[
|
||||
this.attrs.name,
|
||||
this.attrs.operator || this.default_operator,
|
||||
this.get_value()
|
||||
]];
|
||||
}
|
||||
return this.attrs['filter_domain'];
|
||||
return _.extend(
|
||||
{}, domain,
|
||||
{own_values: {self: val}});
|
||||
}
|
||||
});
|
||||
openerp.base.search.CharField = openerp.base.search.Field.extend({
|
||||
|
|
|
@ -30,11 +30,23 @@ class NonLiteralEncoder(simplejson.encoder.JSONEncoder):
|
|||
return super(NonLiteralEncoder, self).default(object)
|
||||
|
||||
def non_literal_decoder(dct):
|
||||
""" Decodes JSON dicts into :class:`Domain` and :class:`Context` based on
|
||||
magic attribute tags.
|
||||
|
||||
Also handles private context section for the domain or section via the
|
||||
``own_values`` dict key.
|
||||
"""
|
||||
if '__ref' in dct:
|
||||
if dct['__ref'] == 'domain':
|
||||
return Domain(None, key=dct['__id'])
|
||||
domain = Domain(None, key=dct['__id'])
|
||||
if 'own_values' in dct:
|
||||
domain.own = dct['own_values']
|
||||
return domain
|
||||
elif dct['__ref'] == 'context':
|
||||
return Context(None, key=dct['__id'])
|
||||
context = Context(None, key=dct['__id'])
|
||||
if 'own_values' in dct:
|
||||
context.own = dct['own_values']
|
||||
return context
|
||||
return dct
|
||||
|
||||
class Domain(object):
|
||||
|
|
Loading…
Reference in New Issue