forked from taylanoaydin/gigl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
257 lines (237 loc) · 8.28 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
from wtforms import SubmitField, TextAreaField, StringField, DateField, SelectField, HiddenField, DecimalField
from wtforms.validators import InputRequired, ValidationError, Length, DataRequired, NumberRange
from wtforms.validators import Optional, ValidationError
from flask_wtf import FlaskForm
from datetime import datetime
import validators
class ApplyForm(FlaskForm):
message = TextAreaField(
'Give them your pitch!', [
InputRequired(), Length(
min=1, max=1000)])
submit = SubmitField('Apply')
class BioEditForm(FlaskForm):
bio = TextAreaField('Bio', [Length(min=0, max=1000)])
submit = SubmitField('Save')
class LinkEditForm(FlaskForm):
def validate_url(form, field):
if (field.data.startswith('http://') or field.data.startswith('https://')):
if not validators.url(field.data):
raise ValidationError('This field must be a valid URL.')
elif field.data and not validators.url('https://' + field.data):
raise ValidationError('This field must be a valid URL.')
link1 = StringField('Link1', validators=[Length(min=0, max=50), validate_url])
link2 = StringField('Link2', validators=[Length(min=0, max=50), validate_url])
link3 = StringField('Link3', validators=[Length(min=0, max=50), validate_url])
link4 = StringField('Link4', validators=[Length(min=0, max=50), validate_url])
submit = SubmitField('Save')
class DeleteGigForm(FlaskForm):
delete = SubmitField('Delete')
confirm = SubmitField('Yes', render_kw={'id': 'confirmButton'})
cancel = SubmitField('No', render_kw={'id': 'cancelButton'})
class SearchForm(FlaskForm):
keyword = StringField('Keyword', validators=[Optional()])
category = SelectField('Category', choices=[
('', 'Any Category'),
('teaching', 'Teaching'),
('research', 'Research'),
('technical', 'Technical'),
('writing', 'Writing'),
('graphic_design', 'Graphic Design'),
('photography_film', 'Photography/Film'),
('events', 'Events'),
('marketing', 'Marketing'),
('administrative', 'Administrative'),
('volunteer', 'Volunteer'),
('fitness', 'Fitness'),
('other', 'Other')
])
submit = SubmitField('Search')
class ProfileSearchForm(FlaskForm):
keyword = StringField('Keyword', validators=[Optional()])
specialty = SelectField('Specialty', choices=[
('', 'Any Specialty'),
('Tutor', 'Tutor'),
('Researcher', 'Researcher'),
('Developer', 'Developer'),
('Writer', 'Writer'),
('Graphic Designer', 'Graphic Designer'),
('Photographer', 'Photographer'),
('Volunteer', 'Volunteer'),
('Fitness Coach', 'Fitness Coach'),
('Cosmetician', 'Cosmetician'),
('Cook', 'Cook'),
('Fashion Designer', 'Fashion Designer'),
('Musician', 'Musician'),
('Choreographer', 'Choreographer'),
('Stylist', 'Stylist'),
('Actor', 'Actor'),
('Miscellaneous', 'Miscellaneous')
])
submit = SubmitField('Search')
class SpecialtySelectForm(FlaskForm):
specialty = SelectField('Specialty', choices=[
('Not Chosen', 'Not Chosen'),
('Tutor', 'Tutor'),
('Researcher', 'Researcher'),
('Developer', 'Developer'),
('Writer', 'Writer'),
('Graphic Designer', 'Graphic Designer'),
('Photographer', 'Photographer'),
('Volunteer', 'Volunteer'),
('Fitness Coach', 'Fitness Coach'),
('Cosmetician', 'Cosmetician'),
('Cook', 'Cook'),
('Fashion Designer', 'Fashion Designer'),
('Musician', 'Musician'),
('Choreographer', 'Choreographer'),
('Stylist', 'Stylist'),
('Actor', 'Actor'),
('Miscellaneous', 'Miscellaneous')
])
submit = SubmitField('Choose')
class SetStatusForm(FlaskForm):
applicantID = HiddenField('AppID')
gigID = HiddenField('GigID')
status = SelectField('Status', choices=[
('YES', 'Accepted'),
('UNDECIDED', 'Pending'),
('NO', 'Rejected')
])
class PostGigForm(FlaskForm):
def validate_end_date(self, field):
if field.errors:
return
if field.data is None:
raise ValidationError(
'End Date is required'
)
elif field.data < datetime.now().date():
raise ValidationError(
"End date cannot be in the past"
)
elif self.start_date.data and field.data < self.start_date.data:
raise ValidationError(
'End date must not be earlier than start date.'
)
def validate_start_date(self, field):
if field.errors:
return
if field.data is None:
raise ValidationError(
'Start Date is required'
)
elif field.data < datetime.now().date():
raise ValidationError(
'Start date cannot be in the past'
)
elif self.end_date.data and field.data > self.end_date.data:
raise ValidationError(
'Start date cannot be after the end date'
)
title = StringField('Title', validators=[InputRequired(), Length(max=46)])
start_date = DateField(
'Start Date',
validators=[
validate_start_date
],
format='%Y-%m-%d')
end_date = DateField(
'End Date',
validators=[
validate_end_date
],
format='%Y-%m-%d')
qualifications = TextAreaField(
'Qualifications', validators=[
InputRequired(), Length(
max=500)])
description = TextAreaField(
'Description', validators=[
InputRequired(), Length(
max=1000)])
price = DecimalField(
'Price', validators=[
InputRequired(), NumberRange(min=0, max=999.99, message='Rate must be between $0 and $999.99')]
)
categories = SelectField(
'Categories',
validators=[
DataRequired(
message='Select A Category'),
InputRequired()],
choices=[
('',
'Select A Category'),
('teaching',
'Teaching'),
('research',
'Research'),
('technical',
'Technical'),
('writing',
'Writing'),
('graphic_design',
'Graphic Design'),
('photography_film',
'Photography/Film'),
('events',
'Events'),
('marketing',
"Marketing"),
('administrative',
"Administrative"),
('volunteer',
"Volunteer"),
('fitness',
'Fitness'),
('other',
'Other')])
submit = SubmitField('Submit')
class EditGigForm(FlaskForm):
title = StringField('Title', validators=[InputRequired(), Length(max=46)])
price = DecimalField(
'Price', validators=[
InputRequired(), NumberRange(min=0, max=999.99, message='Rate must be between $0 and $999.99')])
qualifications = TextAreaField(
'Qualifications', validators=[
InputRequired(), Length(
max=500)])
description = TextAreaField(
'Description', validators=[
InputRequired(), Length(
max=1000)])
categories = SelectField(
'Categories',
validators=[
DataRequired(
message='Select A Category'),
InputRequired()],
choices=[
('',
'Select A Category'),
('teaching',
'Teaching'),
('research',
'Research'),
('technical',
'Technical'),
('writing',
'Writing'),
('graphic_design',
'Graphic Design'),
('photography_film',
'Photography/Film'),
('events',
'Events'),
('marketing',
"Marketing"),
('administrative',
"Administrative"),
('volunteer',
"Volunteer"),
('fitness',
'Fitness'),
('other',
'Other')])
submit = SubmitField('Finish Editing')