class RegistrationForm(ModelForm, FlaskForm): username = StringField('Username', validators=[ DataRequired(), Unique(User.username, message="User with username exists") ]) email = StringField( 'Email', validators=[ DataRequired(), validators.Email(message="Must be a valid email address"), Unique(User.email, message="User with email exists") ]) mobile = IntegerField('Mobile', validators=[DataRequired()]) password = PasswordField('Password', validators=[ DataRequired(), validators.EqualTo( 'confirm_password', message='Passwords must match') ]) confirm_password = PasswordField('Repeat Password')
class SignUpForm(ModelForm): username = StringField('ID', [ DataRequired(message='ID는 필수 항목입니다.'), Length(min=4, max=20, message='%(min)d글자 이상 %(max)d글자 이하로 입력해주세요.'), Unique(UserModel.username, message='이미 존재하는 아이디입니다.') ]) password = PasswordField('Password', [ required(message='비밀번호는 필수 항목입니다.'), Length(min=6, max=20, message='%(min)d 이상 %(max)d 이하로 입력해주세요.') ]) confirm_password = PasswordField('Confirm Password', [ required(message='비밀번호 확인값은 필수 항목입니다.'), EqualTo('password', message='비밀번호와 비밀번호 확인값이 일치하지 않습니다.') ]) name = StringField('Name', [required(message='이름은 필수 항목입니다.')]) nickname = StringField('Nickname', [ required(message='닉네임은 필수 항목입니다.'), Length(min=4, max=16), Unique(UserModel.nickname, message='이미 존재하는 닉네임입니다.') ]) email = EmailField('Email', [ required(message='이메일은 필수 항목입니다.'), Email(message='유효한 이메일 주소를 입력해주세요.'), Unique(UserModel.email, message='이미 존재하는 이메일입니다.') ]) gender = SelectField('Gender', choices=[('male', '남자'), ('female', '여자')])
class AccountForm(ModelForm): class Meta: model = Account first_name = StringField('First name', validators=[DataRequired(), Length(max=50)]) last_name = StringField('Last name', validators=[DataRequired(), Length(max=50)]) username = StringField('Username', validators=[ DataRequired(), Length(max=30), Unique(Account.username, get_session=lambda: db.session) ]) email = EmailField('Email', validators=[ DataRequired(), Length(max=50), Email(), Unique(Account.email, get_session=lambda: db.session) ]) mobile = StringField( 'Mobile number', validators=[ DataRequired(), Length(min=10, max=11), Regexp( '^(\d{10,11})|(\d{3,4}-\d{3}-\d{4})$', message='Input valid mobile number format (e.g. 9123456789)') ]) password = PasswordField( 'Password', validators=[EqualTo('confirm_pass', message='Passwords should match')]) confirm_pass = PasswordField( 'Confirm Password', validators=[EqualTo('password', message='Passwords should match')]) role = SelectField('Account Type', coerce=str, choices=choices_from_dict(Account.ROLE, prepend_blank=False)) old_password = PasswordField('Current Password', validators=[ EqualTo('confirm_old_pass', message='Passwords should match') ]) confirm_old_pass = PasswordField( 'Confirm Current Password', validators=[EqualTo('old_password', message='Passwords should match')])
class SignupForm(ModelForm): email = EmailField(validators=[ DataRequired(), Email(), Unique(User.email, get_session=lambda: db.session) ]) password = PasswordField('Password', [DataRequired(), Length(8, 128)])
class MyForm(ModelForm): name = TextField( validators=[Unique( User.name, get_session=lambda: self.session )] )
class SignupForm(ModelForm): email = EmailField(validators=[ DataRequired(), Email(), Unique(User.email, get_session=lambda: db.session) ]) username = db.Column(db.String(24), unique=True, index=True) password = PasswordField('Password', [DataRequired(), Length(8, 128)])
class AccountForm(ModelForm): class Meta: model = Account first_name = StringField('First name', validators=[DataRequired(), Length(max=50)]) last_name = StringField('Last name', validators=[DataRequired(), Length(max=50)]) username = StringField('Username', validators=[ DataRequired(), Length(max=30), Unique(Account.username, get_session=lambda: db.session) ]) email = EmailField('Email', validators=[ DataRequired(), Length(max=50), Email(), Unique(Account.email, get_session=lambda: db.session) ]) password = PasswordField('Password', validators=[ Optional(), EqualTo('confirm_pass', message='Passwords should match') ]) confirm_pass = PasswordField('Confirm Password', validators=[ Optional(), EqualTo('password', message='Passwords should match') ]) old_password = PasswordField('Current Password', validators=[ EqualTo('confirm_old_pass', message='Passwords should match') ]) confirm_old_pass = PasswordField( 'Confirm Current Password', validators=[EqualTo('old_password', message='Passwords should match')])
class WelcomeForm(ModelForm): username_message = 'Letters, numbers and underscores only please.' username = StringField(validators=[ Unique(User.username, get_session=lambda: db.session), DataRequired(), Length(1, 16), Regexp('^\w+$', message=username_message) ])
class BlogNewsLetterForm(BaseModelForm): email = EmailField('Email', validators=[ InputRequired(), Length(1, 64), Email(), Unique(BlogNewsLetter.email) ]) submit = SubmitField('Submit')
class MyForm(ModelForm): name = TextField(validators=[ Unique([User.name, User.favorite_color], get_session=lambda: self.session) ]) email = TextField() favorite_color = QuerySelectField( query_factory=lambda: self.session.query(Color).all(), allow_blank=True)
class WelcomeForm(ModelForm): username_message = 'Letters, numbers and underscores only please.' username = StringField(validators=[ Unique(User.username), DataRequired(), Length(1, 16), Regexp('^[A-Za-z][A-Za-z0-9_]*$', message=username_message) ])
class SignupForm(ModelForm): name = StringField(validators=[DataRequired()]) username = StringField(validators=[ Unique(User.username, get_session=lambda: db.session, message='This username is already taken!') ]) email = EmailField(validators=[ DataRequired(), Email(), Unique(User.email, get_session=lambda: db.session, message='This email is already in use. Login instead?') ]) password = PasswordField('Create a password', [DataRequired(), Length(8, 128)])
class UpdateCredentials(ModelForm): current_password = PasswordField( 'Current password', [DataRequired(), Length(8, 128), ensure_existing_password_matches]) email = EmailField(validators=[ Email(), Unique(User.email, get_session=lambda: db.session) ]) password = PasswordField('Password', [Optional(), Length(8, 128)])
class NewUserForm(ModelForm): role_list = role_list() username = StringField('Username', validators=[Unique(User.username)]) email = EmailField('Email Address', validators=[ InputRequired(), Email(), Unique(User.email), EqualTo('email2', message='Email addresses must match') ]) email2 = EmailField('Confirm Email', validators=[InputRequired()]) password = PasswordField('Password', validators=[ EqualTo('password2', message='Passwords must match') ]) password2 = PasswordField('Confirm Password') first_name = StringField('First Name') last_name = StringField('Last Name') display_name = StringField('Display Name') image = StringField('Image URL', validators=[URL(), Optional()]) role = RadioField('Role', choices=role_list, default='member') is_enabled = BooleanField('Enabled?')
class WelcomeForm(ModelForm): username_message = 'Letters, numbers and underscores only please.' username = StringField(validators=[ Unique(User.username, get_session=lambda: db.session), DataRequired(), Length(1, 16), # Part of the Python 3.7.x update included updating flake8 which means # we need to explicitly define our regex pattern with r'xxx'. Regexp(r'^\w+$', message=username_message) ])
class ProfileForm(ModelForm, FlaskForm): username = StringField('Username', validators=[ DataRequired(), Unique(User.username, message="User with username exists") ]) email = StringField( 'Email', validators=[ DataRequired(), validators.Email(message="Must be a valid email address"), Unique(User.email, message="User with email exists") ]) mobile = IntegerField('Mobile', validators=[DataRequired()]) first_name = StringField('First Name', validators=[DataRequired()]) last_name = StringField('First Name', validators=[DataRequired()]) email_notifications = BooleanField('Email Notifications') text_notifications = BooleanField('Text Notifications')
class UserForm(FlaskForm, ModelForm): username_message = "Only Letters, Numbers and Special Characters are Considered " username = StringField( validators=[(Unique(User.username, get_session=lambda: db.session)), Optional(), Length(1, 20), Regexp('^/w+$', message=username_message)]) role = SelectField("Privledges", validators=[DataRequired()], choices=choices_from_dict(User.ROLE, prepend_blank=False)) active = BooleanField('Yes, allow this user to sign in')
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
class UpdateCredentials(ModelForm): current_password = PasswordField( 'Current password', [DataRequired(), Length(8, 128), ensure_existing_password_matches]) email = EmailField(validators=[ Email(), Unique(User.email, get_session=lambda: db.session) ]) name = StringField('Full name') username = StringField(validators=[ Unique(User.username, get_session=lambda: db.session, message='That username is already in use.') ]) password = PasswordField('New Password', [Optional(), Length(8, 128)]) confirm = PasswordField( "Repeat New Password", [EqualTo("password", message="Passwords don't match")])
class UserForm(ModelForm): username_message = 'Letters, numbers and underscores only please.' username = StringField(validators=[ Unique(User.username, get_session=lambda: db.session), Optional(), Length(1, 16), Regexp('^\w+$', message=username_message) ]) role = SelectField('Privileges', [DataRequired()], choices=choices_from_dict(User.ROLE, prepend_blank=False)) active = BooleanField('Yes, allow this user to sign in')
class Meta: model = User only = ('name', 'email', 'bio') field_args = { 'name': { 'label': 'Name' }, 'email': { 'label': 'Email', 'validators': (Email(), Unique(User.email)), }, 'bio': { 'label': 'Biography' }, }
class UserForm(ModelForm): username = StringField(validators=[ Unique(User.username), Optional(), Length(1, 16), Regexp( '^[A-Za-z][A-Za-z0-9_.]*$', 0, 'Usernames must have only letters, numbers, dots or ' 'underscores') ]) role = SelectField('Privileges', [DataRequired()], choices=choices_from_dict(User.ROLE, prepend_blank=False)) active = BooleanField('Yes, allow this user to sign in')
class UserForm(ModelForm): username_message = 'Letters, numbers and underscores only please.' username = StringField(validators=[ Unique(User.username, get_session=lambda: db.session), Optional(), Length(1, 16), # Part of the Python 3.7.x update included updating flake8 which means # we need to explicitly define our regex pattern with r'xxx'. Regexp(r'^\w+$', message=username_message) ]) role = SelectField('Privileges', [DataRequired()], choices=choices_from_dict(User.ROLE, prepend_blank=False)) active = BooleanField('Yes, allow this user to sign in')
def _gen_form_dict(self, table_schema): dic = {} for field in table_schema['fields']: validators = [] if field['unique'] == "true": validators.append( Unique( getattr(self.models[table_schema['table_name']], field['name']))) if field['nullable'] == "true": validators.append(DataRequired()) dic[field['name']] = self.FIELD_DICT[field['type']](field['name']) dic['submit'] = SubmitField('Add ' + table_schema['table_name']) dic['reset'] = SubmitField('Reset') print(dic) return dic
class RegisterForm(FlaskForm, ModelForm): email = StringField('Email', validators=[ Email(), DataRequired(), Length(2, 150), Unique(User.email, get_session=lambda: db.session) ]) password = PasswordField('Password', validators=[ Length(6, 64, "At least 6 characters long"), DataRequired(), EqualTo('confirm', message='Passwords must match') ]) confirm = PasswordField('Repeat Password')
class SignupForm(ModelForm): email = EmailField(validators=[ DataRequired(), Email(), Unique(User.email, get_session=lambda: db.session) ]) password = PasswordField('Password', [ DataRequired(), EqualTo("confirm", message="Passwords don't match!"), Length(8, 128) ]) confirm = PasswordField("Repeat Password", [ DataRequired(), EqualTo("password", message="Passwords don't match!"), Length(8, 128) ])
class ProfileForm(ModelForm): """Form for editing :class:`~pygotham.models.User` instances.""" id = HiddenField() twitter_handle = TwitterField('Twitter', validators=(Unique(User.twitter_handle), Optional())) class Meta: model = User only = ('name', 'email', 'bio') field_args = { 'name': { 'label': 'Name' }, 'email': { 'label': 'Email', 'validators': (Email(), Unique(User.email)), }, 'bio': { 'label': 'Biography' }, }
class ChangeProfileForm(BaseModelForm): first_name = StringField('First name', validators=[InputRequired()]) last_name = StringField('Last name', validators=[InputRequired()]) summary_text = TextAreaField('Summary Text or Description') photo = FileField('Profile Image', validators=[Optional(), FileAllowed(images, 'Images only!')]) area_code = StringField('Phone area code only', validators=[InputRequired()]) mobile_phone = IntegerField('Phone numbers only', validators=[InputRequired(), Unique(User.mobile_phone)]) city = StringField('City', validators=[InputRequired()]) state = StringField(u'State', validators=[Optional()]) profession = StringField(u'Profession', validators=[Optional()]) gender = SelectField(u'Gender', choices=[('Male', 'Male'), ('Female', 'Female'), ('Other', 'Other')]) zip = StringField('Zip Code', validators=[InputRequired(), Length(1, 7)]) country = SelectField(u'Select Country', choices=[ ('Afganistan', 'Afghanistan'), ('Albania', 'Albania'), ('Algeria', 'Algeria'), ('American Samoa', 'American Samoa'), ('Andorra', 'Andorra'), ('Angola', 'Angola'), ('Anguilla', 'Anguilla'), ('Antigua & Barbuda', 'Antigua & Barbuda'), ('Argentina', 'Argentina'), ('Armenia', 'Armenia'), ('Aruba', 'Aruba'), ('Australia', 'Australia'), ('Austria', 'Austria'), ('Azerbaijan', 'Azerbaijan'), ('Bahamas', 'Bahamas'), ('Bahrain', 'Bahrain'), ('Bangladesh', 'Bangladesh'), ('Barbados', 'Barbados'), ('Belarus', 'Belarus'), ('Belgium', 'Belgium'), ('Belize', 'Belize'), ('Benin', 'Benin'), ('Bermuda', 'Bermuda'), ('Bhutan', 'Bhutan'), ('Bolivia', 'Bolivia'), ('Bonaire', 'Bonaire'), ('Bosnia & Herzegovina', 'Bosnia & Herzegovina'), ('Botswana', 'Botswana'), ('Brazil', 'Brazil'), ('British Indian Ocean Ter', 'British Indian Ocean Ter'), ('Brunei', 'Brunei'), ('Bulgaria', 'Bulgaria'), ('Burkina Faso', 'Burkina Faso'), ('Burundi', 'Burundi'), ('Cambodia', 'Cambodia'), ('Cameroon', 'Cameroon'), ('Canada', 'Canada'), ('Canary Islands', 'Canary Islands'), ('Cape Verde', 'Cape Verde'), ('Cayman Islands', 'Cayman Islands'), ('Central African Republic', 'Central African Republic'), ('Chad', 'Chad'), ('Channel Islands', 'Channel Islands'), ('Chile', 'Chile'), ('China', 'China'), ('Christmas Island', 'Christmas Island'), ('Cocos Island', 'Cocos Island'), ('Colombia', 'Colombia'), ('Comoros', 'Comoros'), ('Congo', 'Congo'), ('Cook Islands', 'Cook Islands'), ('Costa Rica', 'Costa Rica'), ('Cote DIvoire', 'Cote DIvoire'), ('Croatia', 'Croatia'), ('Cuba', 'Cuba'), ('Curaco', 'Curacao'), ('Cyprus', 'Cyprus'), ('Czech Republic', 'Czech Republic'), ('Denmark', 'Denmark'), ('Djibouti', 'Djibouti'), ('Dominica', 'Dominica'), ('Dominican Republic', 'Dominican Republic'), ('East Timor', 'East Timor'), ('Ecuador', 'Ecuador'), ('Egypt', 'Egypt'), ('El Salvador', 'El Salvador'), ('Equatorial Guinea', 'Equatorial Guinea'), ('Eritrea', 'Eritrea'), ('Estonia', 'Estonia'), ('Ethiopia', 'Ethiopia'), ('Falkland Islands', 'Falkland Islands'), ('Faroe Islands', 'Faroe Islands'), ('Fiji', 'Fiji'), ('Finland', 'Finland'), ('France', 'France'), ('French Guiana', 'French Guiana'), ('French Polynesia', 'French Polynesia'), ('French Southern Ter', 'French Southern Ter'), ('Gabon', 'Gabon'), ('Gambia', 'Gambia'), ('Georgia', 'Georgia'), ('Germany', 'Germany'), ('Ghana', 'Ghana'), ('Gibraltar', 'Gibraltar'), ('Great Britain', 'Great Britain'), ('Greece', 'Greece'), ('Greenland', 'Greenland'), ('Grenada', 'Grenada'), ('Guadeloupe', 'Guadeloupe'), ('Guam', 'Guam'), ('Guatemala', 'Guatemala'), ('Guinea', 'Guinea'), ('Guyana', 'Guyana'), ('Haiti', 'Haiti'), ('Hawaii', 'Hawaii'), ('Honduras', 'Honduras'), ('Hong Kong', 'Hong Kong'), ('Hungary', 'Hungary'), ('Iceland', 'Iceland'), ('Indonesia', 'Indonesia'), ('India', 'India'), ('Iran', 'Iran'), ('Iraq', 'Iraq'), ('Ireland', 'Ireland'), ('Isle of Man', 'Isle of Man'), ('Israel', 'Israel'), ('Italy', 'Italy'), ('Jamaica', 'Jamaica'), ('Japan', 'Japan'), ('Jordan', 'Jordan'), ('Kazakhstan', 'Kazakhstan'), ('Kenya', 'Kenya'), ('Kiribati', 'Kiribati'), ('Korea North', 'Korea North'), ('Korea Sout', 'Korea South'), ('Kuwait', 'Kuwait'), ('Kyrgyzstan', 'Kyrgyzstan'), ('Laos', 'Laos'), ('Latvia', 'Latvia'), ('Lebanon', 'Lebanon'), ('Lesotho', 'Lesotho'), ('Liberia', 'Liberia'), ('Libya', 'Libya'), ('Liechtenstein', 'Liechtenstein'), ('Lithuania', 'Lithuania'), ('Luxembourg', 'Luxembourg'), ('Macau', 'Macau'), ('Macedonia', 'Macedonia'), ('Madagascar', 'Madagascar'), ('Malaysia', 'Malaysia'), ('Malawi', 'Malawi'), ('Maldives', 'Maldives'), ('Mali', 'Mali'), ('Malta', 'Malta'), ('Marshall Islands', 'Marshall Islands'), ('Martinique', 'Martinique'), ('Mauritania', 'Mauritania'), ('Mauritius', 'Mauritius'), ('Mayotte', 'Mayotte'), ('Mexico', 'Mexico'), ('Midway Islands', 'Midway Islands'), ('Moldova', 'Moldova'), ('Monaco', 'Monaco'), ('Mongolia', 'Mongolia'), ('Montserrat', 'Montserrat'), ('Morocco', 'Morocco'), ('Mozambique', 'Mozambique'), ('Myanmar', 'Myanmar'), ('Nambia', 'Nambia'), ('Nauru', 'Nauru'), ('Nepal', 'Nepal'), ('Netherland Antilles', 'Netherland Antilles'), ('Netherlands', 'Netherlands (Holland, Europe)'), ('Nevis', 'Nevis'), ('New Caledonia', 'New Caledonia'), ('New Zealand', 'New Zealand'), ('Nicaragua', 'Nicaragua'), ('Niger', 'Niger'), ('Nigeria', 'Nigeria'), ('Niue', 'Niue'), ('Norfolk Island', 'Norfolk Island'), ('Norway', 'Norway'), ('Oman', 'Oman'), ('Pakistan', 'Pakistan'), ('Palau Island', 'Palau Island'), ('Palestine', 'Palestine'), ('Panama', 'Panama'), ('Papua New Guinea', 'Papua New Guinea'), ('Paraguay', 'Paraguay'), ('Peru', 'Peru'), ('Phillipines', 'Philippines'), ('Pitcairn Island', 'Pitcairn Island'), ('Poland', 'Poland'), ('Portugal', 'Portugal'), ('Puerto Rico', 'Puerto Rico'), ('Qatar', 'Qatar'), ('Republic of Montenegro', 'Republic of Montenegro'), ('Republic of Serbia', 'Republic of Serbia'), ('Reunion', 'Reunion'), ('Romania', 'Romania'), ('Russia', 'Russia'), ('Rwanda', 'Rwanda'), ('St Barthelemy', 'St Barthelemy'), ('St Eustatius', 'St Eustatius'), ('St Helena', 'St Helena'), ('St Kitts-Nevis', 'St Kitts-Nevis'), ('St Lucia', 'St Lucia'), ('St Maarten', 'St Maarten'), ('St Pierre & Miquelon', 'St Pierre & Miquelon'), ('St Vincent & Grenadines', 'St Vincent & Grenadines'), ('Saipan', 'Saipan'), ('Samoa', 'Samoa'), ('Samoa American', 'Samoa American'), ('San Marino', 'San Marino'), ('Sao Tome & Principe', 'Sao Tome & Principe'), ('Saudi Arabia', 'Saudi Arabia'), ('Senegal', 'Senegal'), ('Seychelles', 'Seychelles'), ('Sierra Leone', 'Sierra Leone'), ('Singapore', 'Singapore'), ('Slovakia', 'Slovakia'), ('Slovenia', 'Slovenia'), ('Solomon Islands', 'Solomon Islands'), ('Somalia', 'Somalia'), ('South Africa', 'South Africa'), ('Spain', 'Spain'), ('Sri Lanka', 'Sri Lanka'), ('Sudan', 'Sudan'), ('Suriname', 'Suriname'), ('Swaziland', 'Swaziland'), ('Sweden', 'Sweden'), ('Switzerland', 'Switzerland'), ('Syria', 'Syria'), ('Tahiti', 'Tahiti'), ('Taiwan', 'Taiwan'), ('Tajikistan', 'Tajikistan'), ('Tanzania', 'Tanzania'), ('Thailand', 'Thailand'), ('Togo', 'Togo'), ('Tokelau', 'Tokelau'), ('Tonga', 'Tonga'), ('Trinidad & Tobago', 'Trinidad & Tobago'), ('Tunisia', 'Tunisia'), ('Turkey', 'Turkey'), ('Turkmenistan', 'Turkmenistan'), ('Turks & Caicos Is', 'Turks & Caicos Is'), ('Tuvalu', 'Tuvalu'), ('Uganda', 'Uganda'), ('United Kingdom', 'United Kingdom'), ('Ukraine', 'Ukraine'), ('United Arab Erimates', 'United Arab Emirates'), ('United States of America', 'United States of America'), ('Uraguay', 'Uruguay'), ('Uzbekistan', 'Uzbekistan'), ('Vanuatu', 'Vanuatu'), ('Vatican City State', 'Vatican City State'), ('Venezuela', 'Venezuela'), ('Vietnam', 'Vietnam'), ('Virgin Islands (Brit)', 'Virgin Islands (Brit)'), ('Virgin Islands (USA)', 'Virgin Islands (USA)'), ('Wake Island', 'Wake Island'), ('Wallis & Futana Is', 'Wallis & Futana Is'), ('Yemen', 'Yemen'), ('Zaire', 'Zaire'), ('Zambia', 'Zambia'), ('Zimbabwe', 'Zimbabwe')]) submit = SubmitField('Update')
def unique(column, get_session): return Unique( column, get_session=get_session, message='Not unique' )
"""Admin for user-related models.""" from wtforms.validators import Optional from wtforms_alchemy import Unique from pygotham.admin.utils import model_view from pygotham.fields import TwitterField from pygotham.users import models __all__ = ('RoleModelView', 'UserModelView') RoleModelView = model_view(models.Role, 'Roles', 'Users') UserModelView = model_view( models.User, 'Users', 'Users', column_list=('name', 'email', 'twitter_handle', 'active'), column_searchable_list=('name', 'email'), form_args={ 'twitter_handle': { 'validators': [Unique(models.User.twitter_handle), Optional()], }, }, form_columns=('name', 'email', 'twitter_handle', 'bio', 'active', 'roles'), form_overrides={'twitter_handle': TwitterField}, )