# HG changeset patch # User Adrien Di Mascio # Date 1281422346 -7200 # Node ID 57933567146f08c3dcf52ac0caf812fec98a8992 # Parent ede33e6400ab8da44ff65d509d6aad9a56aaf184 [forms] callable field kwargs now always take form _and_ field parameters + make help kwargs accept a callable too diff -r ede33e6400ab -r 57933567146f web/formfields.py --- a/web/formfields.py Tue Aug 10 08:28:16 2010 +0200 +++ b/web/formfields.py Tue Aug 10 08:39:06 2010 +0200 @@ -73,6 +73,7 @@ FormatConstraint) from cubicweb import Binary, tags, uilib +from cubicweb.utils import support_args from cubicweb.web import INTERNAL_FIELD_VALUE, ProcessFormError, eid_param, \ formwidgets as fw, uicfg @@ -345,7 +346,12 @@ def initial_typed_value(self, form, load_bytes): if self.value is not _MARKER: if callable(self.value): - return self.value(form) + if support_args(self.value, 'form', 'field'): + return self.value(form, self) + else: + warn("[3.10] field's value callback must now take form and field as argument", + DeprecationWarning) + return self.value(form) return self.value formattr = '%s_%s_default' % (self.role, self.name) if hasattr(form, formattr): diff -r ede33e6400ab -r 57933567146f web/views/formrenderers.py --- a/web/views/formrenderers.py Tue Aug 10 08:28:16 2010 +0200 +++ b/web/views/formrenderers.py Tue Aug 10 08:39:06 2010 +0200 @@ -41,7 +41,7 @@ from cubicweb import tags from cubicweb.appobject import AppObject from cubicweb.selectors import is_instance, yes -from cubicweb.utils import json_dumps +from cubicweb.utils import json_dumps, support_args from cubicweb.web import eid_param, formwidgets as fwdgs @@ -53,6 +53,8 @@ name, value, checked, attrs) def field_label(form, field): + if callable(field.label): + return field.label(form, field) # XXX with 3.6 we can now properly rely on 'if field.role is not None' and # stop having a tuple for label if isinstance(field.label, tuple): # i.e. needs contextual translation @@ -133,7 +135,12 @@ help = [] descr = field.help if callable(descr): - descr = descr(form) + if support_args(descr, 'form', 'field'): + descr = descr(form, field) + else: + warn("[3.10] field's help callback must now take form and field as argument", + DeprecationWarning) + descr = descr(form) if descr: help.append('
%s
' % self._cw._(descr)) example = field.example_format(self._cw)