# HG changeset patch # User Thomas De Schampheleire # Date 1480798614 -3600 # Node ID 24b61c257aabc0443f2dfc95c137619b0dd23fd5 # Parent d27077b9df450bf6012feb6465b23af94d422314 forms: wrap LoginForm inside function like other forms All forms except LoginForm are wrapped inside a function. The original purpose of this wrapping seems to be the ability to pass parameters to tweak the form. But, this also has another desired effect: translation of strings wrapped with _ is no longer attempted when reading the class definition, but only when the function is instantiated. In the former case, it is not guaranteed that a translator is actually available because we are not running in standard application context. Align LoginForm with the others. diff -r d27077b9df45 -r 24b61c257aab kallithea/controllers/login.py --- a/kallithea/controllers/login.py Sun Dec 04 22:53:37 2016 +0100 +++ b/kallithea/controllers/login.py Sat Dec 03 21:56:54 2016 +0100 @@ -87,7 +87,7 @@ if request.POST: # import Login Form validator class - login_form = LoginForm() + login_form = LoginForm()() try: c.form_result = login_form.to_python(dict(request.POST)) # form checks for username/password, now we're authenticated diff -r d27077b9df45 -r 24b61c257aab kallithea/model/forms.py --- a/kallithea/model/forms.py Sun Dec 04 22:53:37 2016 +0100 +++ b/kallithea/model/forms.py Sat Dec 03 21:56:54 2016 +0100 @@ -46,30 +46,32 @@ log = logging.getLogger(__name__) -class LoginForm(formencode.Schema): - allow_extra_fields = True - filter_extra_fields = True - username = v.UnicodeString( - strip=True, - min=1, - not_empty=True, - messages={ - 'empty': _('Please enter a login'), - 'tooShort': _('Enter a value %(min)i characters long or more')} - ) +def LoginForm(): + class _LoginForm(formencode.Schema): + allow_extra_fields = True + filter_extra_fields = True + username = v.UnicodeString( + strip=True, + min=1, + not_empty=True, + messages={ + 'empty': _('Please enter a login'), + 'tooShort': _('Enter a value %(min)i characters long or more')} + ) - password = v.UnicodeString( - strip=False, - min=3, - not_empty=True, - messages={ - 'empty': _('Please enter a password'), - 'tooShort': _('Enter %(min)i characters or more')} - ) + password = v.UnicodeString( + strip=False, + min=3, + not_empty=True, + messages={ + 'empty': _('Please enter a password'), + 'tooShort': _('Enter %(min)i characters or more')} + ) - remember = v.StringBoolean(if_missing=False) + remember = v.StringBoolean(if_missing=False) - chained_validators = [v.ValidAuth()] + chained_validators = [v.ValidAuth()] + return _LoginForm def PasswordChangeForm(username):