Spread CDC around forms a bit
This commit is contained in:
parent
3a5a8557e0
commit
b22df32f04
|
@ -5,7 +5,7 @@ from wtforms import (
|
||||||
from wtforms.validators import DataRequired, ValidationError, Optional
|
from wtforms.validators import DataRequired, ValidationError, Optional
|
||||||
from wtforms.widgets.html5 import NumberInput
|
from wtforms.widgets.html5 import NumberInput
|
||||||
|
|
||||||
from amanuensis.config import json_ro
|
from amanuensis.config import root
|
||||||
from amanuensis.lexicon.manage import add_character
|
from amanuensis.lexicon.manage import add_character
|
||||||
from amanuensis.user import UserModel
|
from amanuensis.user import UserModel
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ def user(exists=True):
|
||||||
"not found" if exists else "already exists")
|
"not found" if exists else "already exists")
|
||||||
should_exist = bool(exists)
|
should_exist = bool(exists)
|
||||||
def validate_user(form, field):
|
def validate_user(form, field):
|
||||||
with json_ro('user', 'index.json') as index:
|
with root.user.index() as index:
|
||||||
if (field.data in index.keys()) != should_exist:
|
if (field.data in index.keys()) != should_exist:
|
||||||
raise ValidationError(template.format(field.data))
|
raise ValidationError(template.format(field.data))
|
||||||
return validate_user
|
return validate_user
|
||||||
|
@ -27,7 +27,7 @@ def lexicon(exists=True):
|
||||||
"not found" if exists else "already exists")
|
"not found" if exists else "already exists")
|
||||||
should_exist = bool(exists)
|
should_exist = bool(exists)
|
||||||
def validate_lexicon(form, field):
|
def validate_lexicon(form, field):
|
||||||
with json_ro('lexicon', 'index.json') as index:
|
with root.lexicon.index() as index:
|
||||||
if (field.data in index.keys()) != should_exist:
|
if (field.data in index.keys()) != should_exist:
|
||||||
raise ValidationError(template.format(field.data))
|
raise ValidationError(template.format(field.data))
|
||||||
return validate_lexicon
|
return validate_lexicon
|
||||||
|
@ -36,7 +36,7 @@ def lexicon(exists=True):
|
||||||
# Forms
|
# Forms
|
||||||
class LoginForm(FlaskForm):
|
class LoginForm(FlaskForm):
|
||||||
"""/auth/login/"""
|
"""/auth/login/"""
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
username = StringField('Username', validators=[DataRequired(), user(exists=True)])
|
||||||
password = PasswordField('Password', validators=[DataRequired()])
|
password = PasswordField('Password', validators=[DataRequired()])
|
||||||
remember = BooleanField('Stay logged in')
|
remember = BooleanField('Stay logged in')
|
||||||
submit = SubmitField('Log in')
|
submit = SubmitField('Log in')
|
||||||
|
|
Loading…
Reference in New Issue