-
Notifications
You must be signed in to change notification settings - Fork 2
/
forms.py
205 lines (182 loc) · 11 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
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, RadioField, SubmitField, SelectField, TextAreaField, DateField, ValidationError, DecimalField, FileField
from wtforms.validators import DataRequired, Email, Length, EqualTo, InputRequired
from models import Applicant, Bid
def validate_user_id(form,field):
"""
Custom validator for username
:returns: True if username is unique and is not equal to ' ', False if username is not unique or is equal to ' '.
"""
if not Applicant.is_unique_user_id(field.data) or field.data == ' ':
raise ValidationError('User ID is taken. Please enter another User ID.')
return False
return True
def validate_email(form,field):
"""
Custom validator for username
:returns: True if username is unique and False if username is not unique.
"""
if not Applicant.is_unique_email(field.data):
raise ValidationError('There already exists an account with this email.')
return False
return True
def validate_bid_amount(form, field, demand_id):
"""
Custom validator for BidForm.
Validates if bid_amount is less than the lowest bid, if there is any.
Also validates that bid_amount is a positive number.
"""
bids = Bid.get_bids_for_demand(demand_id)
if len(bids) > 0:
lowest_bid_amount = Bid.get_info(bids[0]).bid_amount
if float(field.data) >= float(lowest_bid_amount):
print(field.data)
raise ValidationError('Bid must be lower than the currently lowest bid.')
class SignupForm(FlaskForm):
"""
Form for the page where the user signs up.
"""
first_name = StringField(label='First Name', id='first_name', validators=[DataRequired('Please enter your first name.')])
last_name = StringField(label='Last Name', id='last_name', validators=[DataRequired('Please enter your last name.')])
email = StringField(label='Email Address', id='email', validators=[DataRequired('Please enter an email address.'), Email(message='Please enter a valid email address.'), validate_email])
phone = StringField(label='Phone Number', id='phone', validators=[DataRequired('Please enter a phone number.')])
user_id = StringField(label='User ID', id='user_id', validators=[DataRequired('Please enter a user ID.'), validate_user_id])
password = PasswordField(label='Password', id='password', validators=[DataRequired('Please enter a password.'), Length(min=8, message='Your password must have at least 8 characters.')])
confirm_password = PasswordField(label='Confirm Password', id ='confirm_password', validators=[DataRequired('Please confirm your password.')])
credit_card = StringField(label='Credit Card Number', id='credit_card', validators=[DataRequired('Please enter the credit card number.')])
credit_card_name = StringField(label='Name of Credit Card Holder', id='credit_card_number', validators=[DataRequired('Please enter the name of the credit card holder.')])
exp_date = DateField(label='Expiration Date', id='credit_card_exp_date', validators=[DataRequired('Please enter the credit card expiration date.')], format='%m/%Y')
security_code = StringField(label='Security Code', id='security_code', validators=[DataRequired('Please enter the security code.')])
billing_address = StringField(label='Billing Address', id='billing_address', validators=[DataRequired('Please enter the billing address.')])
role = SelectField(label='Role', id='role', validators=[DataRequired('Please choose a role.')], choices = [('client','Client'),('developer','Developer')],)
submit = SubmitField('Sign up')
class LoginForm(FlaskForm):
"""
Form for the page where the user signs in.
"""
username = StringField(label='Username', id='username', validators=[DataRequired('Please enter your username.')])
password = PasswordField(label='Password', id='password', validators=[DataRequired('Please enter your password.')])
submit = SubmitField('Sign in')
class ApplicantApprovalForm(FlaskForm):
"""
Form for the page where the superuser can approve/reject an applicant
"""
decision = SelectField(label='Decision', id='decision', validators=[DataRequired('Please select a decision.')], choices = [('approve','Approve'),('reject','Reject')],)
reason = TextAreaField(label='Reason for Decision', validators=[DataRequired('Please provide a reason.')])
submit = SubmitField('Submit')
class ProtestApprovalForm(FlaskForm):
"""
Form for the page where the superuser can remove or keep a user's warning if the user has filed a protest against the warning
"""
decision = SelectField(label='Decision', id='decision', validators=[DataRequired('Please select a decision.')], choices = [('remove','Remove Warning'),('keep','Keep Warning')],)
submit = SubmitField('Submit')
class ProtestForm(FlaskForm):
"""
Form for when user wants to protest a warning.
"""
reason = TextAreaField(label='Reason for Protesting Warning', id='reason', validators=[DataRequired('Please enter a reason for protesting this warning.')])
submit = SubmitField('Submit Protest')
class DemandForm(FlaskForm):
"""
Form for clients to create and post a demand.
"""
title = StringField(label='System Title', id='title',
validators=[DataRequired('Please enter a title for your demand.')])
tags = StringField(label='Tags')
specifications = TextAreaField(label='System description',
id='specifications',
validators=[DataRequired('Please enter specifications for the demand.')])
bidding_deadline = DateField(label='Deadline for Bidding', id='bidding_deadline',
validators=[DataRequired('Please provide a deadline for bidding.')])
submission_deadline = DateField(label='Deadline for Submitting the System', id='submission_deadline',
validators=[DataRequired('Please provide a deadline for submitting the final system.')])
submit = SubmitField('Post Demand')
class BidForm(FlaskForm):
"""
Form for developers to make bids for a demand.
"""
bid_amount = DecimalField(label='Bid Amount', id='bid_amount', validators=[DataRequired('Please enter an amount to bid.')])
# , validate_bid_amount])
submit = SubmitField('Make a Bid')
class JustifyDeveloperChoiceForm(FlaskForm):
"""
Form for clients to justify their reason for choosing a developer who did
not submit the lowest bid for their system demand.
"""
reason = TextAreaField(label='Reason for not choosing the developer with the lowest bid.',
validators=[DataRequired('Please provide a reason for not choosing the developer with the lowest bid.')])
submit = SubmitField('Submit Reason')
class BecomeUserForm(FlaskForm):
"""
Form for when applicant wants to become user
"""
use_prev_credentials = SelectField(label='Do you want to keep your current login credentials?', id='use_prev_credentials', validators=[DataRequired('Please choose a role.')], choices = [('yes','Yes'),('no','No')],)
username = StringField(label='User ID', id='user_id', validators=[DataRequired('Please enter a user ID.'), validate_user_id])
password = PasswordField(label='Password', id='password', validators=[DataRequired('Please enter a password.'), Length(min=8, message='Your password must have at least 8 characters.')])
confirm_password = PasswordField(label='Confirm Password', id='confirm_password', validators=[DataRequired('Please confirm your password.')])
submit = SubmitField('Submit')
class SubmitSystemForm(FlaskForm):
"""
Form for a developer to submit a system for a client's demand.
"""
system = FileField('System file', validators=[DataRequired('Please submit a file containing the system.')])
submit = SubmitField('Submit')
class RatingForm(FlaskForm):
"""
Form for rating after a project is finished.
"""
rating = RadioField(label='Rating',
choices=[
(1,'<i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i>'),
(2,'<i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i>'),
(3,'<i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i>'),
(4,'<i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star-o" aria-hidden="true"></i>'),
(5,'<i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i><i class="fa fa-star" aria-hidden="true"></i>')],
coerce=int)
submit = SubmitField('Submit')
class RatingMessageForm(FlaskForm):
"""
Form for sending message after a low rating.
"""
message = TextAreaField(label='Send Feedback', id="message", validators=[DataRequired('Please give a rating.')] )
submit = SubmitField('Submit')
class TransactionApprovalForm(FlaskForm):
"""
Form for the page where the superuser can approve/reject a transaction
"""
decision = SelectField(label='Please select your decision', id='decision', validators=[DataRequired('Please choose an option.')], choices = [('approve','Approve'),('deny','Deny')],)
submit = SubmitField('Submit')
class DeleteAccountForm(FlaskForm):
"""
Form for users to delete their account
"""
delete = SubmitField(label='Yes')
cancel = SubmitField(label='No')
class DeleteAccountApprovalForm(FlaskForm):
"""
Form for the page where the superuser can approve/reject a transaction
"""
decision = SelectField(label='Please select your decision', id='decision', validators=[DataRequired('Please choose an option.')], choices = [('approve','Approve'),('deny','Deny')],)
submit = SubmitField('Submit')
class AddFundsForm(FlaskForm):
"""
Form for user to add funds to their acccount.
"""
amount = DecimalField(label='Amount', id='amount', validators=[DataRequired('Please enter an amount to add to your funds.')])
# , validate_bid_amount])
submit = SubmitField('Add Funds')
class EditProfileForm(FlaskForm):
"""
Form for users to edit their profile
"""
password = PasswordField(label='Change Password', id='password')
confirm_password = PasswordField(label='Confirm Password', id='confirm_password')
first_name = StringField(label='First Name', id='first_name', validators=[DataRequired('Please enter your first name.')])
last_name = StringField(label='Last Name', id='last_name', validators=[DataRequired('Please enter your last name.')])
phone = StringField(label='Phone Number', id='phone', validators=[DataRequired('Please enter a phone number.')])
email = StringField(label="Email Address", id='email', validators=[DataRequired('Please enter an email address.'), Email(message='Please enter a valid email address.')])
resume = FileField(label="Resume", id='resume')
about = StringField(label="About Me", id='about')
portfolio = StringField(label="Portfolio Link", id='portfolio')
interests = StringField(label="Interests", id='interests')
submit = SubmitField('Submit')