26 |
26 |
27 Let first see the base class for fields: |
27 Let first see the base class for fields: |
28 |
28 |
29 .. autoclass:: cubicweb.web.formfields.Field |
29 .. autoclass:: cubicweb.web.formfields.Field |
30 |
30 |
31 Now, you usually don't use that class but one of the concret field classes |
31 Now, you usually don't use that class but one of the concrete field classes |
32 described below, according to what you want to edit. |
32 described below, according to what you want to edit. |
33 |
33 |
34 Basic fields |
34 Basic fields |
35 '''''''''''' |
35 '''''''''''' |
36 |
36 |
105 _MARKER = nullobject() |
105 _MARKER = nullobject() |
106 |
106 |
107 class Field(object): |
107 class Field(object): |
108 """This class is the abstract base class for all fields. It hold a bunch |
108 """This class is the abstract base class for all fields. It hold a bunch |
109 of attributes which may be used for fine control of the behaviour of a |
109 of attributes which may be used for fine control of the behaviour of a |
110 concret field. |
110 concrete field. |
111 |
111 |
112 **Attributes** |
112 **Attributes** |
113 |
113 |
114 All the attributes described below have sensible default value which may be |
114 All the attributes described below have sensible default value which may be |
115 overriden by named arguments given to field's constructor. |
115 overriden by named arguments given to field's constructor. |
347 return self.initial_typed_value(form, load_bytes) |
347 return self.initial_typed_value(form, load_bytes) |
348 |
348 |
349 def initial_typed_value(self, form, load_bytes): |
349 def initial_typed_value(self, form, load_bytes): |
350 if self.value is not _MARKER: |
350 if self.value is not _MARKER: |
351 if callable(self.value): |
351 if callable(self.value): |
|
352 # pylint: disable=E1102 |
352 if support_args(self.value, 'form', 'field'): |
353 if support_args(self.value, 'form', 'field'): |
353 return self.value(form, self) |
354 return self.value(form, self) |
354 else: |
355 else: |
355 warn("[3.10] field's value callback must now take form and " |
356 warn("[3.10] field's value callback must now take form and " |
356 "field as argument (%s)" % self, DeprecationWarning) |
357 "field as argument (%s)" % self, DeprecationWarning) |
387 It should return a list of tuple (label, value), where value |
388 It should return a list of tuple (label, value), where value |
388 *must be an unicode string*, not a typed value. |
389 *must be an unicode string*, not a typed value. |
389 """ |
390 """ |
390 assert self.choices is not None |
391 assert self.choices is not None |
391 if callable(self.choices): |
392 if callable(self.choices): |
|
393 # pylint: disable=E1102 |
392 if getattr(self.choices, 'im_self', None) is self: |
394 if getattr(self.choices, 'im_self', None) is self: |
393 vocab = self.choices(form=form, **kwargs) |
395 vocab = self.choices(form=form, **kwargs) |
394 elif support_args(self.choices, 'form', 'field'): |
396 elif support_args(self.choices, 'form', 'field'): |
395 vocab = self.choices(form=form, field=self, **kwargs) |
397 vocab = self.choices(form=form, field=self, **kwargs) |
396 else: |
398 else: |
397 try: |
399 try: |
398 vocab = self.choices(form=form, **kwargs) |
400 vocab = self.choices(form=form, **kwargs) |
399 warn('[3.6] %s: choices should now take ' |
401 warn('[3.6] %s: choices should now take ' |
400 'the form and field as named arguments' % self, |
402 'the form and field as named arguments' % self, |
401 DeprecationWarning) |
403 DeprecationWarning) |
402 except TypeError: |
404 except TypeError: |
403 warn('[3.3] %s: choices should now take ' |
405 warn('[3.3] %s: choices should now take ' |
404 'the form and field as named arguments' % self, |
406 'the form and field as named arguments' % self, |
405 DeprecationWarning) |
407 DeprecationWarning) |
406 vocab = self.choices(req=form._cw, **kwargs) |
408 vocab = self.choices(req=form._cw, **kwargs) |
407 else: |
409 else: |
408 vocab = self.choices |
410 vocab = self.choices |