diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 097b9ab79e9..f75ef21f87d 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -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: diff --git a/addons/base/static/openerp/js/base_views.js b/addons/base/static/openerp/js/base_views.js index ec06f446280..4b6009acb16 100644 --- a/addons/base/static/openerp/js/base_views.js +++ b/addons/base/static/openerp/js/base_views.js @@ -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({ diff --git a/openerpweb/nonliterals.py b/openerpweb/nonliterals.py index 4dc6abfcba0..a0805c9c0c2 100644 --- a/openerpweb/nonliterals.py +++ b/openerpweb/nonliterals.py @@ -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):