to ease overriding of field.choices using *function* (set using autoform_field_kwargs), give the field as named argument
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 25 Jan 2010 19:16:35 +0100
changeset 4338 0eb7efcbcee1
parent 4337 27ea69e2cfea
child 4339 fe93b670343d
to ease overriding of field.choices using *function* (set using autoform_field_kwargs), give the field as named argument
web/formfields.py
--- a/web/formfields.py	Mon Jan 25 19:13:17 2010 +0100
+++ b/web/formfields.py	Mon Jan 25 19:16:35 2010 +0100
@@ -255,11 +255,18 @@
         assert self.choices is not None
         if callable(self.choices):
             try:
-                vocab = self.choices(form=form)
+                if getattr(self.choices, 'im_self', None) is self:
+                    vocab = self.choices(form=form)
+                else:
+                    vocab = self.choices(form=form, field=self)
             except TypeError:
-                warn('[3.3] vocabulary method (eg field.choices) should now take '
-                     'the form instance as argument', DeprecationWarning)
-                vocab = self.choices(req=form._cw)
+                warn('[3.6]  %s: choices should now take '
+                     'the form and field as named arguments', self)
+                try:
+                    vocab = self.choices(req=form._cw)
+                except TypeError:
+                    warn('[3.3]  %s: choices should now take '
+                         'the form and field as named arguments', self)
         else:
             vocab = self.choices
         if vocab and not isinstance(vocab[0], (list, tuple)):