tw.forms.validators

The majority of validators come directly from FormEncode. However, tw.forms overrides some, and provides some additional validators. It is recommended to always access validators through tw.forms.validators (rather than importing FormEncode directly), to ensure any overrides in tw.forms are applied. Only the tw.forms validators are documented here; consult the FormEncode documentation for others.

DateTimeConverter

class tw.forms.validators.DateTimeConverter(format='%Y/%m/%d %H:%M', tzinfo=None, *args, **kwargs)

Converts Python date and datetime objects into string representation and back.

Messages

badFormat:
Invalid datetime format
badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Empty values not allowed
noneType:
The input must be a string (not None)

UnicodeString

class tw.forms.validators.UnicodeString(inputEncoding=None, outputEncoding=None, **kw)

The FormEncode UnicodeString validator encodes strings as utf-8 for display. However, this is not desired behaviour in tw.forms, as Genshi will fail when it receives such strings. Instead, this validator renders Python unicode objects where possible, strings otherwise.

Messages

badEncoding:
Invalid data or incorrect encoding
badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
tooLong:
Enter a value less than %(max)i characters long
tooShort:
Enter a value %(min)i characters long or more

SecureTicketValidator

class tw.forms.validators.SecureTicketValidator(widget=None, session_secret_cb=None, **kw)

This validator helps you avoid cross-site request forgeries (CSRF) - a kind of web application security vulnerability.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)