-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
70 lines (56 loc) · 3.92 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from random import choices
from flask_wtf import FlaskForm
#from flask_login import current_user
from flask_wtf.file import FileField, FileAllowed
from wtforms import StringField, IntegerField, PasswordField, SubmitField, \
BooleanField, TextAreaField, SelectMultipleField, HiddenField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
from models import AppUser
""" Form to Log In """
class LoginForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
# This field allows users to remain logged in after a period under a secure cookie
remember_user = BooleanField('Remember Me')
submit = SubmitField('Login')
""" Form to Register"""
class RegistrationForm(FlaskForm):
firstname = StringField('First Name', validators=[DataRequired(), Length(min=2, max=10)])
lastname = StringField('Last Name', validators=[DataRequired(), Length(min=5, max=10)])
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
repeat_password = PasswordField('Repeat Password', validators=[DataRequired(), EqualTo('password', message='Passwords must match')])
options=['12 available options:', 'French', 'Spanish', 'English', 'Portuguese', 'Chinese', 'German','Khoisan', 'Korean', 'Swahili', 'Japanese', 'Russian', 'Arabic']
options.sort()
fluent_languages = SelectMultipleField('Select your native and fluent language(s)', validators=[DataRequired()], choices=options)
other_languages = SelectMultipleField('Select the language(s) you want to learn', validators=[DataRequired()], choices=options)
interests = TextAreaField('Describe your Interests and ideal language exchange partner', validators=[DataRequired(), Length(max=300)])
lookup_address = StringField('Search for your Street name and House number')
coord_latitude = HiddenField('Latitude',validators=[DataRequired()])
coord_longitude = HiddenField('Longitude', validators=[DataRequired()])
submit = SubmitField('Confirm Registration')
def validate_email(self, email):
app_user = AppUser.query.filter_by(email=email.data).first()
if app_user:
raise ValidationError('This email is taken, please select a different one.')
""" Form to Update user profile Info """
class UpdateProfileForm(FlaskForm):
firstname = StringField('First Name', validators=[DataRequired(), Length(min=2, max=10)])
lastname = StringField('Last Name', validators=[DataRequired(), Length(min=2, max=10)])
options=['12 available options:', 'French', 'Spanish', 'English', 'Portuguese', 'Chinese', 'German','Khoisan', 'Korean', 'Swahili', 'Japanese', 'Russian', 'Arabic']
options.sort()
fluent_languages = SelectMultipleField('Your native and fluent language(s)', validators=[DataRequired()], choices=options)
other_languages = SelectMultipleField('Language(s) you want to learn', validators=[DataRequired()], choices=options)
interests = TextAreaField('Describe your Interests and ideal language exchange partner', validators=[DataRequired(), Length(max=300)])
picture = FileField('Upload profile picture', validators=[FileAllowed(['jpg', 'AVIF'])])
lookup_address = StringField('Update your Street name and House number')
coord_latitude = HiddenField('Latitude',validators=[DataRequired()])
coord_longitude = HiddenField('Longitude', validators=[DataRequired()])
submit = SubmitField('Update')
class NewLocationForm(FlaskForm):
description = StringField('Location description',
validators=[DataRequired(), Length(min=1, max=80)])
lookup_address = StringField('Search address')
coord_latitude = HiddenField('Latitude',validators=[DataRequired()])
coord_longitude = HiddenField('Longitude', validators=[DataRequired()])
submit = SubmitField('Create Location')