How to use the wtforms.StringField 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 crflynn / pypistats.org / pypistats / views / general.py View on Github external
blueprint = Blueprint("general", __name__, template_folder="templates")


MODELS = [
    OverallDownloadCount,
    PythonMajorDownloadCount,
    PythonMinorDownloadCount,
    SystemDownloadCount,
]


class MyForm(FlaskForm):
    """Search form."""

    name = StringField("Package: ", validators=[DataRequired()])


@blueprint.route("/", methods=("GET", "POST"))
def index():
    """Render the home page."""
    form = MyForm()
    if form.validate_on_submit():
        package = form.name.data
        return redirect(f"/search/{package.lower()}")
    package_count = \
        RecentDownloadCount.query.filter_by(category="month").count()
    return render_template(
        "index.html",
        form=form,
        user=g.user,
        package_count=package_count
github miguelgrinberg / microblog / app / auth / forms.py View on Github external
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
from flask_babel import _, lazy_gettext as _l
from app.models import User


class LoginForm(FlaskForm):
    username = StringField(_l('Username'), validators=[DataRequired()])
    password = PasswordField(_l('Password'), validators=[DataRequired()])
    remember_me = BooleanField(_l('Remember Me'))
    submit = SubmitField(_l('Sign In'))


class RegistrationForm(FlaskForm):
    username = StringField(_l('Username'), validators=[DataRequired()])
    email = StringField(_l('Email'), validators=[DataRequired(), Email()])
    password = PasswordField(_l('Password'), validators=[DataRequired()])
    password2 = PasswordField(
        _l('Repeat Password'), validators=[DataRequired(),
                                           EqualTo('password')])
    submit = SubmitField(_l('Register'))

    def validate_username(self, username):
        user = User.query.filter_by(username=username.data).first()
        if user is not None:
            raise ValidationError(_('Please use a different username.'))

    def validate_email(self, email):
        user = User.query.filter_by(email=email.data).first()
        if user is not None:
            raise ValidationError(_('Please use a different email address.'))
github lingthio / Flask-User / flask_user / forms.py View on Github external
first_name = StringField(_('First name'), validators=[validators.DataRequired()])
    last_name = StringField(_('Last name'), validators=[validators.DataRequired()])

    submit = SubmitField(_('Update'))


class LoginForm(FlaskForm):
    """Login form."""
    next = HiddenField()         # for login.html
    reg_next = HiddenField()     # for login_or_register.html

    username = StringField(_('Username'), validators=[
        validators.DataRequired(_('Username is required')),
    ])
    email = StringField(_('Email'), validators=[
        validators.DataRequired(_('Email is required')),
        validators.Email(_('Invalid Email'))
    ])
    password = PasswordField(_('Password'), validators=[
        validators.DataRequired(_('Password is required')),
    ])
    remember_me = BooleanField(_('Remember me'))

    submit = SubmitField(_('Sign in'))

    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)
        user_manager =  current_app.user_manager
        if user_manager.USER_ENABLE_USERNAME and user_manager.USER_ENABLE_EMAIL:
            # Renamed 'Username' label to 'Username or Email'
            self.username.label.text = _('Username or Email')
github its-a-feature / Apfell / app / forms / payloads_form.py View on Github external
from sanic_wtf import SanicForm
from wtforms import StringField, BooleanField, SubmitField, IntegerField, SelectField, SelectMultipleField
from wtforms.validators import DataRequired


class Payloads_JXA_Form(SanicForm):
    callback_host = StringField('Callback Host', validators=[DataRequired()])
    callback_port = IntegerField('Callback Port', validators=[DataRequired()])
    obfuscation = BooleanField('Obfuscation')
    output_directory = StringField('Output Directory', validators=[DataRequired()])
    callback_interval = IntegerField('Callback Interval', validators=[DataRequired()])
    default_tag = StringField('Default tag')
    c2_profile = SelectField('C2 Profile', coerce=str)
    commands = SelectMultipleField('Commands', coerce=str)
    submit = SubmitField('Create Payload')
github mush42 / oy-cms / starlit / wtf_utils.py View on Github external
class RichTextAreaField(TextAreaField):
        widget = RichTextAreaWidget()

class FileSelectorInput(TextInput):
    def __init__(self, field=None, render_args=None, **kw):
        self.html_class = kw.pop('class', '')
        self.render_args = render_args
        super(FileSelectorInput, self).__init__(field, **kw)

    def __call__(self, field, **kwargs):
        kwargs['class'] = kwargs.get('class', '') + ' file-input'
        kwargs['data-name'] = self.render_args['name']
        html = super(FileSelectorInput, self).__call__(field, type='hidden', **kwargs)
        return html + render_template('canella/admin/widgets/file-selector.html', **self.render_args)

class FileSelectorField(StringField):
    def __init__(self, render_args=None, *args, **kwargs):
        if render_args is None:
            render_args = dict()
        self.render_args = render_args
        self.render_args.setdefault('button_text', kwargs.pop('button_text', lazy_gettext('Select A File')))
        super(FileSelectorField, self).__init__(*args, **kwargs)
        self.render_args.setdefault('label', kwargs.pop('label', lazy_gettext('File')))
        self.render_args.setdefault('name', self.name)
        self.widget = FileSelectorInput(render_args=self.render_args)
github jwag956 / flask-security / flask_security / forms.py View on Github external
form.user = _datastore.find_user(
        case_insensitive=uia_email.get("case_insensitive", False), email=field.data
    )
    if form.user is None:
        raise ValidationError(get_message("USER_DOES_NOT_EXIST")[0])


class Form(BaseForm):
    def __init__(self, *args, **kwargs):
        if current_app.testing:
            self.TIME_LIMIT = None
        super().__init__(*args, **kwargs)


class EmailFormMixin:
    email = StringField(
        get_form_field_label("email"), validators=[email_required, email_validator]
    )


class UserEmailFormMixin:
    user = None
    email = StringField(
        get_form_field_label("email"),
        validators=[email_required, email_validator, valid_user_email],
    )


class UniqueEmailFormMixin:
    email = StringField(
        get_form_field_label("email"),
        validators=[email_required, email_validator, unique_user_email],
github BAM-PFA / edith / edith / app / admin / forms.py View on Github external
namespace = StringField('Namespace for XML/XPATH queries')
	username = StringField("Database user's username", validators=[DataRequired()])
	credentials = StringField('Database user password', validators=[DataRequired()])
	description = StringField('Database description')
	primaryAssetID = StringField('Field name for primary ID of an asset')
	secondaryAssetID = StringField('Field name for secondary ID of an asset')

	submit = SubmitField('Submit')

class MetadataFieldForm(FlaskForm):
	"""
	Form for admin to create or edit metadata field
	"""
	fieldName = StringField('Field display name', validators=[DataRequired()])
	fieldUniqueName = StringField('Unique name for system', validators=[DataRequired()])
	fieldSourceName = StringField('Name of field in source as applicable')
	fieldCategory = StringField(
			'Category field belongs to. Please choose '\
			'"Event","Communications", "Film Collection", or "General".')
	dataSource_id = QuerySelectField(
		query_factory=lambda: Data_Source.query.all(),
		get_pk=lambda x: x.id,
		get_label="dbName",
		allow_blank=True,
		blank_text=u'Select a data source'
		)
	rsFieldID = StringField("ResourceSpace reference ID for field")
	description = StringField('Database description')

	submit = SubmitField('Submit')
github block-cat / flask_manager / app / auth / forms.py View on Github external
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired, Length


class LoginForm(FlaskForm):
    username = StringField('用户名', validators=[DataRequired(), Length(1, 64), ])
    password = PasswordField('密码', validators=[DataRequired()])
    enable_otp = StringField("是否开启二次验证", default=False)
    otp_code = StringField("二次验证码")
    rememberme = BooleanField('记住我')
    submit = SubmitField('提交')
github okpy / ok / server / forms.py View on Github external
if not super(NewCourseForm, self).validate():
            return False

        # Ensure the name has the right format:
        if not utils.is_valid_endpoint(self.offering.data, COURSE_ENDPOINT_FORMAT):
            self.offering.errors.append(('The name should look like univ/course101/semYY where "sem" is one of (fa, su, sp, au, wi)'))
            return False

        course = Course.query.filter_by(offering=self.offering.data).first()
        if course:
            self.offering.errors.append('That offering already exists.')
            return False
        return True

class CourseUpdateForm(BaseForm):
    institution = StringField('School (e.g. UC Berkeley)',
                              validators=[validators.optional()])
    display_name = StringField('Course Name (e.g CS61A)',
                               validators=[validators.required()])
    website = StringField('Course Website',
                          validators=[validators.optional(), validators.url()])
    active = BooleanField('Activate Course', default=True)
    timezone = SelectField('Course Timezone', choices=[(t, t) for t in pytz.common_timezones])
    autograder_url = StringField('Autograder Endpoint (Optional)',
                           validators=[validators.optional(), validators.url()])

class PublishScores(BaseForm):
    published_scores = MultiCheckboxField(
        'Published Scores',
        choices=[(kind, kind.title()) for kind in SCORE_KINDS],
    )
github gae-init / gae-init / main / control / admin.py View on Github external
bitbucket_key = wtforms.StringField(model.Config.bitbucket_key._verbose_name, filters=[util.strip_filter])
  bitbucket_secret = wtforms.StringField(model.Config.bitbucket_secret._verbose_name, filters=[util.strip_filter])
  dropbox_app_key = wtforms.StringField(model.Config.dropbox_app_key._verbose_name, filters=[util.strip_filter])
  dropbox_app_secret = wtforms.StringField(model.Config.dropbox_app_secret._verbose_name, filters=[util.strip_filter])
  facebook_app_id = wtforms.StringField(model.Config.facebook_app_id._verbose_name, filters=[util.strip_filter])
  facebook_app_secret = wtforms.StringField(model.Config.facebook_app_secret._verbose_name, filters=[util.strip_filter])
  github_client_id = wtforms.StringField(model.Config.github_client_id._verbose_name, filters=[util.strip_filter])
  github_client_secret = wtforms.StringField(model.Config.github_client_secret._verbose_name, filters=[util.strip_filter])
  google_client_id = wtforms.StringField(model.Config.google_client_id._verbose_name, filters=[util.strip_filter])
  google_client_secret = wtforms.StringField(model.Config.google_client_secret._verbose_name, filters=[util.strip_filter])
  instagram_client_id = wtforms.StringField(model.Config.instagram_client_id._verbose_name, filters=[util.strip_filter])
  instagram_client_secret = wtforms.StringField(model.Config.instagram_client_secret._verbose_name, filters=[util.strip_filter])
  linkedin_api_key = wtforms.StringField(model.Config.linkedin_api_key._verbose_name, filters=[util.strip_filter])
  linkedin_secret_key = wtforms.StringField(model.Config.linkedin_secret_key._verbose_name, filters=[util.strip_filter])
  mailru_app_id = wtforms.StringField(model.Config.mailru_app_id._verbose_name, filters=[util.strip_filter])
  mailru_app_secret = wtforms.StringField(model.Config.mailru_app_secret._verbose_name, filters=[util.strip_filter])
  microsoft_client_id = wtforms.StringField(model.Config.microsoft_client_id._verbose_name, filters=[util.strip_filter])
  microsoft_client_secret = wtforms.StringField(model.Config.microsoft_client_secret._verbose_name, filters=[util.strip_filter])
  reddit_client_id = wtforms.StringField(model.Config.reddit_client_id._verbose_name, filters=[util.strip_filter])
  reddit_client_secret = wtforms.StringField(model.Config.reddit_client_secret._verbose_name, filters=[util.strip_filter])
  twitter_consumer_key = wtforms.StringField(model.Config.twitter_consumer_key._verbose_name, filters=[util.strip_filter])
  twitter_consumer_secret = wtforms.StringField(model.Config.twitter_consumer_secret._verbose_name, filters=[util.strip_filter])
  vk_app_id = wtforms.StringField(model.Config.vk_app_id._verbose_name, filters=[util.strip_filter])
  vk_app_secret = wtforms.StringField(model.Config.vk_app_secret._verbose_name, filters=[util.strip_filter])
  yahoo_consumer_key = wtforms.StringField(model.Config.yahoo_consumer_key._verbose_name, filters=[util.strip_filter])
  yahoo_consumer_secret = wtforms.StringField(model.Config.yahoo_consumer_secret._verbose_name, filters=[util.strip_filter])


@app.route('/admin/auth/', methods=['GET', 'POST'])
@auth.admin_required
def admin_auth():
  config_db = model.Config.get_master_db()