@@ -10,17 +10,32 @@ class WtfBaseField(BaseField):
1010 number of field parameters, and settings on behalf
1111 of document model form generator for WTForm.
1212
13+ @param validators: wtf model form field validators.
14+ @param filters: wtf model form field filters.
1315 """
1416
15- def __init__ (self , validators = None , ** kwargs ):
17+ def __init__ (self , validators = None , filters = None , ** kwargs ):
18+
19+ self .validators = \
20+ self ._ensure_callable_or_list (validators , 'validators' )
21+ self .filters = self ._ensure_callable_or_list (filters , 'filters' )
22+
1623 BaseField .__init__ (self , ** kwargs )
1724
18- # Ensure we have a list of validators
19- if validators is not None :
20- if callable (validators ):
21- validators = [validators ]
25+
26+ def _ensure_callable_or_list (self , field , msg_flag ):
27+ """
28+ Ensure the value submitted via field is either
29+ a callable object to convert to list or it is
30+ in fact a valid list value.
31+
32+ """
33+ if field is not None :
34+ if callable (field ):
35+ field = [field ]
2236 else :
23- msg = "Argument 'validators ' must be a list value"
24- if not isinstance (validators , list ):
37+ msg = "Argument '%s ' must be a list value" % msg_flag
38+ if not isinstance (field , list ):
2539 raise TypeError (msg )
26- self .validators = validators
40+
41+ return field
0 commit comments