def _setup_unbound_fields(self): for field_name, field_rules in self.rules().items(): field_type, validators = self._parse_rules(field_name, field_rules) field = (field_name, UnboundField(field_type, field_name, validators)) self._unbound_fields.append(field)
def bind_field(_: Any, form: DynamicForm, unbound_field: UnboundField, options: Dict[Any, Any]) -> Field: """ Customize how fields are bound by stripping all whitespace. :param form: The form :param unbound_field: The unbound field :param options: The field options :returns: The bound field """ filters = unbound_field.kwargs.get("filters", []) filters.append(lambda x: x.strip() if isinstance(x, str) else x) return unbound_field.bind(form=form, filters=filters, **options)
def __init__(self, *args, **kwargs): unbound = UnboundField(HoneypotField, _(u"Leave this field empty")) self._unbound_fields.append((FIELD_NAME, unbound)) super(Honeypot, self).__init__(*args, **kwargs)
def __new__(cls, *args, **kwargs): if '_form' in kwargs and '_name' in kwargs: return super(Field, cls).__new__(cls) else: return UnboundField(cls, *args, **kwargs)