Added autocompletion on fields.Char
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Added autocompletion on fields.Char
|
||||
* Remove ir.default
|
||||
* Add type, last user and last modification on ir.attachment
|
||||
* Rename datas into data on ir.attachment
|
||||
|
||||
@@ -198,6 +198,17 @@ A single line string field.
|
||||
If true, the value of the field is translatable. The value readed and
|
||||
stored will depend on the ``language`` defined in the context.
|
||||
|
||||
.. attribute:: Char.autocomplete
|
||||
|
||||
A list of field names. If this attribute is set, the client will call the
|
||||
method ``autocomplete_<field name>`` of the model when the user changes one
|
||||
of those field value. The method signature is::
|
||||
|
||||
autocomplete_<field name>(values)
|
||||
|
||||
This method must return a list of string that will populate the
|
||||
ComboboxEntry in the client.
|
||||
|
||||
.. warning::
|
||||
Note that you may need to set :attribute:`Fields.loading` to ``lazy``
|
||||
when :attribute:`Char.translate` is ``True``.
|
||||
|
||||
@@ -104,8 +104,6 @@ attlist.field &= attribute readonly { "0" | "1" }?
|
||||
attlist.field &=
|
||||
[ a:defaultValue = "0" ] attribute tree_invisible { "0" | "1" }?
|
||||
attlist.field &= attribute mode { text }?
|
||||
attlist.field &=
|
||||
[ a:defaultValue = "0" ] attribute completion { "0" | "1" }?
|
||||
attlist.field &=
|
||||
[ a:defaultValue = "0" ] attribute invisible { "0" | "1" }?
|
||||
attlist.field &= attribute sum { text }?
|
||||
|
||||
@@ -369,16 +369,6 @@
|
||||
<attribute name="mode"/>
|
||||
</optional>
|
||||
</define>
|
||||
<define name="attlist.field" combine="interleave">
|
||||
<optional>
|
||||
<attribute name="completion" a:defaultValue="0">
|
||||
<choice>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
</optional>
|
||||
</define>
|
||||
<define name="attlist.field" combine="interleave">
|
||||
<optional>
|
||||
<attribute name="invisible" a:defaultValue="0">
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
from trytond.model.fields.field import Field
|
||||
|
||||
def autocomplete_validate(value):
|
||||
if value:
|
||||
assert isinstance(value, list), 'autocomplete must be a list'
|
||||
|
||||
|
||||
class Char(Field):
|
||||
'''
|
||||
@@ -13,7 +17,8 @@ class Char(Field):
|
||||
def __init__(self, string='', size=None, help='', required=False,
|
||||
readonly=False, domain=None, states=None, change_default=False,
|
||||
translate=False, select=0, on_change=None, on_change_with=None,
|
||||
depends=None, order_field=None, context=None, loading='eager'):
|
||||
depends=None, order_field=None, context=None, loading='eager',
|
||||
autocomplete=None):
|
||||
'''
|
||||
:param translate: A boolean. If ``True`` the field is translatable.
|
||||
:param size: A integer. If set defines the maximum size of the values.
|
||||
@@ -24,6 +29,17 @@ class Char(Field):
|
||||
on_change=on_change, on_change_with=on_change_with,
|
||||
depends=depends, order_field=order_field, context=context,
|
||||
loading=loading)
|
||||
self.__autocomplete = None
|
||||
self.autocomplete = autocomplete if autocomplete else None
|
||||
self.translate = translate
|
||||
self.size = size
|
||||
__init__.__doc__ += Field.__init__.__doc__
|
||||
|
||||
def _get_autocomplete(self):
|
||||
return self.__autocomplete
|
||||
|
||||
def _set_autocomplete(self, value):
|
||||
autocomplete_validate(value)
|
||||
self.__autocomplete = value
|
||||
|
||||
autocomplete = property(_get_autocomplete, _set_autocomplete)
|
||||
|
||||
@@ -94,14 +94,12 @@ class Model(WarningErrorMixin):
|
||||
and not isinstance(field.selection, (list, tuple)) \
|
||||
and field.selection not in self._rpc:
|
||||
self._rpc[field.selection] = False
|
||||
if field.on_change:
|
||||
on_change = 'on_change_' + field_name
|
||||
if on_change not in self._rpc:
|
||||
self._rpc[on_change] = False
|
||||
if field.on_change_with:
|
||||
on_change_with = 'on_change_with_' + field_name
|
||||
if on_change_with not in self._rpc:
|
||||
self._rpc[on_change_with] = False
|
||||
|
||||
for attribute in ('on_change', 'on_change_with', 'autocomplete'):
|
||||
function_name = '%s_%s' % (attribute, field_name)
|
||||
if (getattr(field, attribute, False)
|
||||
and callable(getattr(self, function_name, False))):
|
||||
self._rpc.setdefault(function_name, False)
|
||||
|
||||
def __getattr__(self, name):
|
||||
# Search if a function exists in inherits parents
|
||||
@@ -503,6 +501,7 @@ class Model(WarningErrorMixin):
|
||||
'on_change',
|
||||
'add_remove',
|
||||
'on_change_with',
|
||||
'autocomplete',
|
||||
'sort',
|
||||
'datetime_field',
|
||||
'loading',
|
||||
|
||||
Reference in New Issue
Block a user