-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
135 lines (118 loc) · 7.59 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
from re import sub
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, IntegerField
from wtforms.validators import DataRequired, Length, EqualTo, ValidationError, NumberRange
from models import Consignment, Manager, Employee, Customer, Office, Truck
class signUpManager(FlaskForm):
Name = StringField(label = 'Name', validators=[DataRequired(), Length(min=2, max=30)])
address = StringField(label = 'Address', validators=[DataRequired(), Length(min=2, max=100)])
phoneNumber = StringField(label = 'Contact No.', validators=[DataRequired(), Length(min=10, max=10)])
email = StringField(label = 'Email ID', validators=[DataRequired()])
password1 = PasswordField(label = 'Password', validators=[DataRequired(), Length(min=8)])
password2 = PasswordField(label = 'Re-enter Password', validators=[DataRequired(), EqualTo('password1')])
submit = SubmitField(label = 'Sign Up')
class loginManager(FlaskForm):
email = StringField(label = 'Email ID', validators=[DataRequired()])
password = PasswordField(label = 'Password', validators=[DataRequired(), Length(min=8)])
submit = SubmitField(label = 'Login')
class loginEmployee(FlaskForm):
email = StringField(label = 'Email ID', validators=[DataRequired()])
password = PasswordField(label = 'Password', validators=[DataRequired(), Length(min=8)])
submit = SubmitField(label = 'Login')
class signUpCustomer(FlaskForm):
def validate_email(self, email):
customer = Customer.query.filter_by(email = email.data).first()
if customer:
raise ValidationError('Email already exists')
name = StringField(label = 'Name', validators=[DataRequired(), Length(min=2, max=30)])
address = StringField(label = 'Address', validators=[DataRequired(), Length(min=2, max=100)])
branchID = IntegerField(label = 'Branch ID', validators=[DataRequired(), NumberRange(min = 1, max=999999999)])
phoneNumber = StringField(label = 'Contact No.', validators=[DataRequired(), Length(min=10, max=10)])
email = StringField(label = 'Email ID', validators=[DataRequired()])
password1 = PasswordField(label = 'Password', validators=[DataRequired(), Length(min=8)])
password2 = PasswordField(label = 'Re-enter Password', validators=[DataRequired(), EqualTo('password1')])
submit = SubmitField(label = 'Sign Up')
class loginCustomer(FlaskForm):
email = StringField(label = 'Email ID', validators=[DataRequired()])
password = PasswordField(label = 'Password', validators=[DataRequired(), Length(min=8)])
submit = SubmitField(label = 'Login')
class createEmployee(FlaskForm):
def validate_email(self, email):
employee = Employee.query.filter_by(email = email.data).first()
if employee:
raise ValidationError('Email already exists')
def validate_branchID(self, branchID):
branch = Office.query.filter_by(officeID = branchID.data).first()
if branch is None:
raise ValidationError('Branch ID does not exist')
name = StringField(label = 'Name', validators=[DataRequired(), Length(min=2, max=30)])
address = StringField(label = 'Address', validators=[DataRequired(), Length(min=2, max=100)])
phoneNumber = StringField(label = 'Contact No.', validators=[DataRequired(), Length(min=10, max=10)])
branchID = IntegerField(label = 'Branch ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
email = StringField(label = 'Email ID', validators=[DataRequired()])
password1 = PasswordField(label = 'Password', validators=[DataRequired(), Length(min=8)])
password2 = PasswordField(label = 'Re-enter Password', validators=[DataRequired(), EqualTo('password1')])
submit = SubmitField(label = 'Add Employee')
class createOffice(FlaskForm):
def validate_officeID(self, officeID):
office = Office.query.filter_by(officeID = officeID.data).first()
if office:
raise ValidationError('ID already exists')
officeID = IntegerField(label = 'ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
address = StringField(label = 'Address', validators=[DataRequired(), Length(min=2, max=100)])
phoneNumber = StringField(label = 'Contact No.', validators=[DataRequired(), Length(min=10, max=10)])
rate = IntegerField(label = 'Rate', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
submit = SubmitField(label = 'Add Office')
class addTruck(FlaskForm):
def validate_truckID(self, truckID):
truck = Truck.query.filter_by(truckID = truckID.data).first()
if truck:
raise ValidationError('ID already exists')
def validate_currentBranchID(self, currentBranchID):
branch = Office.query.filter_by(officeID = currentBranchID.data).first()
if branch is None:
raise ValidationError('Branch ID does not exist')
truckID = IntegerField(label = 'Truck ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
currentBranchID = IntegerField(label = 'Branch ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
submit = SubmitField(label = 'Add Truck')
class branchConsignmentDetails(FlaskForm):
def validate_branchID(self, branchID):
branch = Office.query.filter_by(officeID = branchID.data).first()
if branch is None:
raise ValidationError('Branch ID does not exist')
branchID = IntegerField(label = 'Branch ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
submit = SubmitField(label = 'View Details')
class placeOrder(FlaskForm):
def validate_senderID(self,senderID):
sender_ = Customer.query.filter_by(customerID = senderID.data).first()
if sender_ is None:
raise ValidationError('Sender ID does not exist')
def validate_receiverID(self,receiverID):
receiver_ = Customer.query.filter_by(customerID = receiverID.data).first()
if receiver_ is None:
raise ValidationError('Receiver ID does not exist')
senderID = IntegerField(label = 'Sender ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
receiverID = IntegerField(label = 'Receiver ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
volume = IntegerField(label = 'Volume', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
submit = SubmitField(label = 'Place Order')
class viewBill(FlaskForm):
def validate_consignmentID(self, consignmentID):
consignment = Consignment.query.filter_by(consignmentID = consignmentID.data).first()
if consignment is None:
raise ValidationError('Consignment ID does not exist')
consignmentID = IntegerField(label = 'Consignment ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
submit = SubmitField(label = 'View Bill')
class viewTruckStatus(FlaskForm):
def validate_truckID(self, truckID):
truck = Truck.query.filter_by(truckID = truckID.data).first()
if truck is None:
raise ValidationError('Truck ID does not exist')
truckID = IntegerField(label = 'Truck ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
submit = SubmitField(label = 'View Truck Status')
class trackConsignment(FlaskForm):
def validate_consignmentID(self, consignmentID):
consignment = Consignment.query.filter_by(consignmentID = consignmentID.data).first()
if consignment is None:
raise ValidationError('Consignment ID does not exist')
consignmentID = IntegerField(label = 'Consignment ID', validators=[DataRequired(), NumberRange(min=1, max=999999999)])
submit = SubmitField(label = 'Track Consignment Status')