Changeset - 24b61c257aab
[Not reviewed]
default
0 2 0
Thomas De Schampheleire - 9 years ago 2016-12-03 21:56:54
thomas.de.schampheleire@gmail.com
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.
2 files changed with 24 insertions and 22 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/login.py
Show inline comments
 
@@ -87,7 +87,7 @@ class LoginController(BaseController):
 

	
 
        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
kallithea/model/forms.py
Show inline comments
 
@@ -46,30 +46,32 @@ from kallithea.model import validators a
 
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):
0 comments (0 inline, 0 general)