How to use the wtforms.fields 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 wtforms / wtforms / tests / ext_sqlalchemy.py View on Github external
def test_convert_basic(self):
        self.assertRaises(TypeError, model_form, None)
        self.assertRaises(ModelConversionError, model_form, self.Course)
        form_class = model_form(self.Course, exclude=['students'])
        form = form_class()
        self.assertEqual(len(list(form)), 7)
        assert isinstance(form.cost, fields.DecimalField)
        assert isinstance(form.has_prereqs, fields.BooleanField)
        assert isinstance(form.started, fields.DateTimeField)
github jstacoder / flask-cms / flask_cms / auth / forms.py View on Github external
from ext import Form
from wtforms import fields, validators

class BaseUserForm(Form):
    email = fields.StringField('Email Address',validators=[validators.InputRequired(),
                                validators.Email()])
    password = fields.PasswordField('Password',validators=[validators.DataRequired()])

class UserLoginForm(BaseUserForm):
    keep_me_logged_in = fields.BooleanField('Keep Me Logged In')


class UserSignupForm(BaseUserForm):
    confirm = fields.PasswordField('Confirm',validators=[validators.DataRequired(),
                                validators.EqualTo('password')])
github kawa-kokosowa / bubblebbs / bubblebbs / moderate.py View on Github external
class PostModelView(MyModelView):
    column_filters = (
        'id',
        'name',
        'ip_address', 
        'tripcode',
        'message',
    )
    column_default_sort = ('id', True)


class PageModelView(MyModelView):
    column_display_pk = True
    form_columns = ('title', 'slug', 'source')
    form_overrides = dict(
        source=fields.TextAreaField,
    )
    form_widget_args = dict(
        source={
            'placeholder': 'Enter new contents with markdown',
        },
    )

    def _page_body(view, context, model, name):
        return Markup(models.Post.parse_markdown(model.slug, model.body, allow_all=True))
    column_formatters = {
        'body': _page_body,
    }

    def create_form(self):
        form = super(MyModelView, self).create_form()
        if ('source') in request.args.keys():
github agdsn / pycroft / web / form / fields / core.py View on Github external
)


class FileField(wtforms.fields.FileField):
    widget = decorate_field(
        wtforms.fields.FileField,
        BootstrapStandardDecorator,
        BootstrapFormGroupDecorator
    )


# No need to decorate wtforms.fields.HiddenField
HiddenField = wtforms.fields.HiddenField


class SubmitField(wtforms.fields.SubmitField):
    widget = decorate_field(
        wtforms.fields.SubmitField,
        BootstrapFormGroupDecorator
    )


class QuerySelectField(
    wtforms.ext.sqlalchemy.fields.QuerySelectField
):
    widget = decorate_field(
        wtforms.ext.sqlalchemy.fields.QuerySelectField,
        BootstrapFormControlDecorator,
        BootstrapStandardDecorator,
        BootstrapFormGroupDecorator
    )
github Remmeauth / remme-core / remme / shared / forms / node_account.py View on Github external
from wtforms import fields, validators

from .base import ProtoForm


class NodeAccountInternalTransferPayloadForm(ProtoForm):
    value = fields.IntegerField(validators=[
        validators.DataRequired(message='Could not transfer with zero amount.')
    ])


class NodeAccountGenesisForm(ProtoForm):
    value = fields.IntegerField()


class CloseMasternodePayloadForm(ProtoForm):
    pass
github oldarmyc / pitchfork / pitchfork / manage_globals / forms.py View on Github external
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from flask.ext.wtf import Form
from wtforms import fields, validators


class VerbSet(Form):
    name = fields.TextField('Verb:', validators=[validators.required()])
    active = fields.BooleanField('Active:')
    submit = fields.SubmitField('Submit')


class RegionSet(Form):
    name = fields.TextField('Name:', validators=[validators.required()])
    abbreviation = fields.TextField(
        'Abbreviation:',
        validators=[validators.required()]
    )
    submit = fields.SubmitField('Submit')
github inveniosoftware / invenio / invenio / modules / oauth2server / forms.py View on Github external
html.append(u'<div class="col-md-3">')
        html.append(u'<label class="checkbox-inline" for="%s">' % field_id)
        html.append(u'<input> ' % widgets.html_params(**options))
        html.append("%s <br><small class="text-muted">%s</small>" % (
            value, label.help_text)
        )
        html.append(u'</label></div>')
    html.append(u'')

    return u''.join(html)


#
# Redirect URI field
#
class RedirectURIField(fields.TextAreaField):

    """Process redirect URI field data."""

    def process_formdata(self, valuelist):
        """Process form data."""
        if valuelist:
            self.data = "\n".join([
                x.strip() for x in
                filter(lambda x: x, "\n".join(valuelist).splitlines())
            ])

    def process_data(self, value):
        """Process data."""
        self.data = "\n".join(value)
github closeio / flask-common / flask_common / forms.py View on Github external
def conv_List(self, model, field, kwargs):
        for field_name in self.expand_references:
            if getattr(model, field_name) == field:

                unbound_field = self.convert(model, field.field, {})
                kwargs = {
                    'validators': [],
                    'filters': [],
                }
                return fields.FieldList(unbound_field, min_entries=0, **kwargs)

        else:
            #return super(ModelConverter, self).conv_List(model, field, kwargs)
            return AdminModelConverter.conv_List(self, model, field, kwargs)
github bslatkin / dpxdt / dependencies / WTForms / 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 flask-admin / flask-admin / examples / pymongo / simple.py View on Github external
# Form list
    form_list = InlineFieldList(InlineFormField(InnerForm))


class UserView(ModelView):
    column_list = ('name', 'email', 'password')
    column_sortable_list = ('name', 'email', 'password')

    form = UserForm


# Tweet view
class TweetForm(form.Form):
    name = fields.StringField('Name')
    user_id = fields.SelectField('User', widget=Select2Widget())
    text = fields.StringField('Text')

    testie = fields.BooleanField('Test')


class TweetView(ModelView):
    column_list = ('name', 'user_name', 'text')
    column_sortable_list = ('name', 'text')

    column_filters = (filters.FilterEqual('name', 'Name'),
                      filters.FilterNotEqual('name', 'Name'),
                      filters.FilterLike('name', 'Name'),
                      filters.FilterNotLike('name', 'Name'),
                      filters.BooleanEqualFilter('testie', 'Testie'))

    column_searchable_list = ('name', 'text')