How to use the wtforms.fields.TextField function in WTForms

To help you get started, we’ve selected a few WTForms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kvesteri / wtforms-alchemy / tests / test_unique_validator.py View on Github external
def _test_syntax(self, column, expected_dict):
        class MyForm(ModelForm):
            name = TextField()
            email = TextField()

        validator = Unique(
            column,
            get_session=lambda: self.session
        )
        form = MyForm()
        if not hasattr(form, 'Meta'):
            form.Meta = lambda: None
        form.Meta.model = User
        result = validator._syntaxes_as_tuples(form, form.name, column)
        assert result == expected_dict
github sdayu / pumbaa / pumbaa / forms / accounts.py View on Github external
if request_user.password != request.secret_manager.get_hash_password(field.data):
        raise validators.ValidationError(
            'Old password mismatch')

class Login(Form): 
    username = fields.TextField('Username or Email', validators=[validators.InputRequired()])
    password = fields.PasswordField('Password', validators=[validators.InputRequired()])
    came_from = fields.HiddenField('Came form')
    
class Register(Form):
    username = fields.TextField('Username', validators=[validators.InputRequired(), validators.Length(min=2), validate_username])
    email = html5.EmailField('Email', validators=[validators.InputRequired(), validators.Email(), validate_email])
    password = fields.PasswordField('Password', validators=[validators.InputRequired(), validators.Length(min=6), validators.EqualTo('password_conf', message="password mismatch")])
    password_conf = fields.PasswordField('Password confirm', validators=[validators.InputRequired()])
    first_name = fields.TextField('First name', validators=[validators.InputRequired()])
    last_name = fields.TextField('Last name', validators=[validators.InputRequired()])
    agree_term = fields.BooleanField('Agree term', validators=[validators.InputRequired()])
    
class Password(Form):
    old_password = fields.PasswordField('Old password', validators=[validators.InputRequired(), validators.Length(min=6), validate_old_password])
    password = fields.PasswordField('Password', validators=[validators.InputRequired(), validators.Length(min=6), validators.EqualTo('password_conf', message="password mismatch")])
    password_conf = fields.PasswordField('Password confirm', validators=[validators.InputRequired()])

class DisplayName(Form):
    display_name = fields.TextField('Display Name', validators=[validators.InputRequired(), validate_display_name])
    first_name = fields.TextField('First Name', validators=[validators.InputRequired()])
    last_name = fields.TextField('Last Name', validators=[validators.InputRequired()])
github leasunhy / GalaxyOJ / server / forms.py View on Github external
real_name = TextField('Real name')
    note = TextAreaField('Note')

    submit = SubmitField('Update')

    def validate_old_password(self, field):
        u = User.query.filter_by(login_name=self.login_name.data).first()
        if u is None or not u.verify_password(field.data):
            raise ValidationError('Password is invalid.')

class EditUserProfile(Form):
    login_name = TextField('Username', validators = [Required()])
    password = PasswordField('Password')
    email = TextField('Email', validators = [Email()])
    nickname = TextField('Nickname')
    signature = TextField('Signature')
    real_name = TextField('Real name')
    note = TextAreaField('Note')
    submit = SubmitField('Edit')

class ManageUserProfile(EditUserProfile):
    privilege_level = SelectField('Set privilege level', 
            coerce=int, 
            choices=[(0, 'Normal'), (1, 'Administrator')])
    def validate_privilege_level(self, field):
        if not field.data in {0, 1}:
            raise ValidationError('Privilege level invalid')

class UserRegisterForm(Form):
    login_name = TextField('Username', validators = [Required()])
    password = PasswordField('Password', validators = [Required()])
    confirmpwd = PasswordField('Confirm password',
github moraes / tipfy / source / lib / wtforms / ext / appengine / db.py View on Github external
def get_TextField(kwargs):
    """
    Returns a ``TextField``, applying the ``db.StringProperty`` length limit
    of 500 bytes.
    """
    kwargs['validators'].append(validators.length(max=500))
    return f.TextField(**kwargs)
github NoGameNoLife00 / mybolg / forms.py View on Github external
#encoding=utf-8
"""
用户登录表单
"""
from flask.ext.wtf import Form
from wtforms.fields import TextField, BooleanField, TextAreaField, PasswordField
from wtforms.validators import required, Required, Length, DataRequired, ValidationError
from werkzeug.security import generate_password_hash, check_password_hash
from blogapp import app, db
from data_model import User
from flask.ext.login import LoginManager
from config import REGISTRATION_CODE

# Define login and registration forms (for flask-login)
class LoginForm(Form):
    login = TextField(validators=[required()])
    password = PasswordField(validators=[required()])

    def validate_login(self, field):
        user = self.get_user()

        if user is None:
            raise ValidationError('Invalid user')

        # we're comparing the plaintext pw with the the hash from the db
        # if not check_password_hash(user.password, self.password.data):
        # to compare plain text passwords use
        if user.password != self.password.data:
            raise ValidationError('Invalid password')

    def get_user(self):
        return db.session.query(User).filter_by(login=self.login.data).first()
github kamalgill / flask-appengine-template / src / wtforms / ext / appengine / db.py View on Github external
def get_TextField(kwargs):
    """
    Returns a ``TextField``, applying the ``db.StringProperty`` length limit
    of 500 bytes.
    """
    kwargs['validators'].append(validators.length(max=500))
    return f.TextField(**kwargs)
github Yubico / yubiadmin / yubiadmin / apps / admin.py View on Github external
'/etc/yubico/admin/yubiadmin.conf',
    [
        ('interface', python_handler('INTERFACE', '127.0.0.1')),
        ('port', python_handler('PORT', 8080)),
        ('username', python_handler('USERNAME', 'yubiadmin')),
        ('password', python_handler('PASSWORD', 'yubiadmin')),
    ]
)


class ConnectionForm(ConfigForm):
    legend = 'Connection'
    description = 'Server network interface settings'
    config = admin_config

    interface = TextField('Listening Interface', [IPAddress()])
    port = IntegerField('Listening Port', [NumberRange(1, 65535)])


class CredentialsForm(ConfigForm):
    legend = 'Credentials'
    description = 'Credentials for accessing YubiAdmin'
    config = admin_config

    username = TextField('Username', [])
    password = PasswordField('Password',
                             widget=PasswordInput(hide_value=False))


class YubiAdmin(App):
    """
    YubiAdmin
github oldarmyc / pitchfork / pitchfork / forms.py View on Github external
name = fields.TextField('Verb:', validators=[validators.required()])
    active = fields.BooleanField('Active:', default=True)

    def validate_name(self, field):
        found = g.db.api_settings.find_one(
            {
                'verbs.name': self.name.data.upper()
            }
        )
        if found:
            raise validators.ValidationError('Duplicate verb')


class RegionSet(Form):
    name = fields.TextField('Name:', validators=[validators.required()])
    abbreviation = fields.TextField(
        'Abbreviation:',
        validators=[validators.required()]
    )

    def validate_abbreviation(self, field):
        found = g.db.api_settings.find_one(
            {
                'regions.abbreviation': self.abbreviation.data.upper()
            }
        )
        if found:
            raise validators.ValidationError('Duplicate abbreviation')

    def validate_name(self, field):
        regex = re.compile(
            '^%s$' % self.name.data,
github leasunhy / GalaxyOJ / server / forms.py View on Github external
def validate_email(self, field):
        u = User.query.filter(User.email==field.data).first()
        if u:
            raise ValidationError('Email already exists.')

class EditProblemForm(Form):
    title = TextField('Title', validators = [Required()])
    problem_desc = TextAreaField('Description', filters=[sanitize])
    input_desc = TextAreaField('Input Format', filters=[sanitize])
    output_desc = TextAreaField('Output Format', filters=[sanitize])
    sample_input = TextAreaField('Sample Input', filters=[sanitize])
    sample_output = TextAreaField('Sample Output', filters=[sanitize])
    source = TextField('Source')
    time_limit = TextField('Time Limit', validators = [Required()])
    memory_limit = TextField('Memory Limit', validators = [Required()])
    submit = SubmitField('Submit')

class EditContestForm(Form):
    title = TextField('Title', validators=[Required()])
    description = TextAreaField('Description')
    start_time = DateTimeField('Start time', validators=[Required()])
    end_time = DateTimeField('End time', validators=[Required()])
    passcode = TextField('Password')
    submit = SubmitField('Submit')

    def validate_end_time(self, field):
        if self.start_time.data > field.data:
            raise ValidationError('End time should be after start time')

class EditPostForm(Form):
    title = TextField('Title', validators = [Required()])