Add support for domain_<field name> method

issue4126
review6501002
This commit is contained in:
Cédric Krier
2014-09-13 15:14:56 +02:00
parent fb3eb72d16
commit 16aa948e3d
3 changed files with 16 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add support for domain_<field name> method
* Refactor configuration file and command line
* Use the context of the relation field for instanciation
* Use a configuration field for logging
+12
View File
@@ -188,6 +188,18 @@ Default value
See :ref:`default value <topics-fields_default_value>`
Searching
=========
A class method could be defined for each field which must return a SQL
expression for the given domain instead of the default one.
The method signature is::
domain_<field name>(domain, tables)
Where ``domain`` is the simple :ref:`domain <topics-domain>` clause and
``tables`` is a nested dictionary, see :meth:`~Field.convert_domain`.
Ordering
========
+3
View File
@@ -251,6 +251,9 @@ class Field(object):
table, _ = tables[None]
name, operator, value = domain
assert name == self.name
method = getattr(Model, 'domain_%s' % name, None)
if method:
return method(domain, tables)
Operator = SQL_OPERATORS[operator]
column = self.sql_column(table)
expression = Operator(column, self._domain_value(operator, value))