from wtforms import HiddenField, PasswordField, validators from wtfpeewee.orm import model_form, ModelConverter from flask.ext.wtf import Form from utils import Unique, ReadonlyField from models import Group, Pad from widgets import TextArea CreateGroup = model_form(Group, base_class=Form, exclude=['api_id'], field_args={ 'name': {'validators': [ validators.Required(), validators.Regexp('^[a-zA-Z1-9_-]+$', message=u'Invalid group name ' '(only simple characters, numbers, - and _).'), validators.Regexp('^[a-zA-Z1-9]', message=u'Group name should not ' 'start with a special character.'), Unique(Group, Group.name, message=u'A group with this name ' 'already exists.')] }, 'description': {'widget': TextArea(rows=7)}}) ChangeGroup = model_form(Group, base_class=Form, exclude=['api_id'], field_args={ 'description': {'widget': TextArea(rows=7)}}, converter=ModelConverter(overrides={'name': ReadonlyField})) CreatePad = model_form( Pad, base_class=Form, exclude=['api_id', 'created', 'group'], field_args={ 'name': {'validators': [ validators.Required(), validators.Regexp('^[a-zA-Z1-9_-]+$', message=u'Invalid pad name ' '(only simple characters, numbers, - and _).'), validators.Regexp('^[a-zA-Z1-9]', message=u'Pad name should not ' 'start with a special character.')]}}, converter=ModelConverter(overrides={'password': PasswordField})) class DeleteForm(Form): sure = HiddenField('are you sure', default='yes')