-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForms.py
199 lines (157 loc) · 11.3 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
from wtforms import Form, StringField, SelectField, validators, BooleanField, PasswordField, FileField, DecimalField, IntegerField, TextAreaField, RadioField
from wtforms.fields.html5 import DateField
from wtforms.validators import ValidationError
from wtforms_components import TimeField, DateRange, TimeRange
from datetime import datetime,date
import re
subCatList = [('', 'Select')
, ('BabyAccessories', 'Baby - Accessories')
, ('BabyVitamins', 'Baby - Baby Vitamins')
, ('Diapers', 'Baby - Diapers')
, ('MilkPowder&Food', 'Baby - Milk Powder & Food')
, ('Toiletries', 'Baby - Toiletries')
, ('CosmeticsAccessories', 'Cosmetics - Accessories')
, ('Eyes', 'Cosmetics - Eyes')
, ('Face', 'Cosmetics - Face')
, ('Lips', 'Cosmetics - Lips')
, ('MakeupRemover', 'Cosmetics - Makeup Remover')
, ('Nails', 'Cosmetics - Nails')
, ('Conditioner', 'Hair Care - Conditioner')
, ('HairDye', 'Hair Care - Hair Dye')
, ('HairStyling', 'Hair Care - Hair Styling')
, ('Shampoo', 'Hair Care - Shampoo')
, ('Treatment', 'Hair Care - Treatment')
, ('Eye&EarCare', 'Health - Eye & Ear Care')
, ('FamilyPlanning', 'Health - Family Planning')
, ('FirstAid&Surgical', 'Health - First Aid & Surgical')
, ('Pain&Fever', 'Health - Pain & Fever')
, ('Supplements', 'Health - Supplements')
, ('SkinCareAccessories', 'Skin Care - Accessories')
, ('Anti-acne', 'Skin Care - Anti-acne')
, ('Facial', 'Skin Care - Facial')
, ('Hand&Body', 'Skin Care - Hand & Body')
, ('LipCare', 'Skin Care - Lip Care')
, ('SunCare', 'Skin Care - Sun Care')
, ('Bath&HandCleansing', 'Toiletries - Bath & Hand Cleansing')
, ('OralCare', 'Toiletries - Oral Care')
, ('SanitaryCare', 'Toiletries - Sanitary Care')
, ('Tissues&Wipes', 'Toiletries - Tissues & Wipes')]
class EditProductForm(Form):
activated = BooleanField('')
productName = StringField('Product Name', [validators.DataRequired(message='This is a required field.')
, validators.Length(min=1, max=100, message='Product name has to be less than 100 characters.')])
brand = StringField('Brand', [validators.DataRequired(message='This is a required field.')
, validators.Length(min=1, max=50, message='Brand name is too long.')])
subCategory = SelectField('Sub-Category', [validators.DataRequired(message='This is a required field.')], choices=subCatList, default='')
price = DecimalField('Price', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')], places=2)
description = TextAreaField('Description', [validators.DataRequired(message='This is a required field.')])
quantity = IntegerField('In-Stock', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')])
stockThreshold = IntegerField('Alert if stock falls below', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')])
serialNo = StringField('Serial No.')
class CreateProductForm(Form):
productName = StringField('Product Name', [validators.DataRequired(message='This is a required field.')
, validators.Length(min=1, max=100, message='Product name has to be less than 100 characters.')])
brand = StringField('Brand', [validators.DataRequired(message='This is a required field.')
, validators.Length(min=1, max=50, message='Brand name is too long.')])
subCategory = SelectField('Sub-Category', [validators.DataRequired(message='This is a required field.')], choices=subCatList, default='')
price = DecimalField('Price', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')], places=2)
description = TextAreaField('Description', [validators.DataRequired(message='This is a required field.')])
quantity = IntegerField('In-Stock', [validators.DataRequired(message='This is a required field.')])
stockThreshold = IntegerField('Alert if stock falls below', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')])
activated = BooleanField('')
class LoginForm(Form):
username = StringField('Username', [validators.Length(min=1, max=25), validators.DataRequired()])
password = PasswordField('Password', [validators.DataRequired()])
class RegistrationForm(Form):
email = StringField('Email Address', [validators.Length(min=6, max=35)])
username = StringField('Username', [validators.Length(min=4, max=25)])
password = PasswordField('New Password', [
validators.DataRequired(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
class EditProfileForm(Form):
username = StringField('Username', [validators.Length(min=1, max=25), validators.DataRequired()])
address = TextAreaField('Address')
phone = IntegerField('Contact Number',[validators.NumberRange(min=80000000, max=99999999, message="Please enter a valid phone number")])
email = StringField('Contact Email', [validators.Length(min=6, max=35)])
password = StringField("Password", [validators.DataRequired(), validators.Regexp('^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$', message = "Password must be 8-20 characters, and contain at least 1 capital letter, 1 lowercase letter and a number.")])
newpassword = StringField('New Password')
class NoCollectForm(Form):
home_delivery = BooleanField("Home Delivery (+$12)")
cardlist = [('visa','Visa'),
('mastercard', 'MasterCard')]
class DeliveryForm(Form):
name = StringField('Cardholder Name',[validators.DataRequired()])
phone = IntegerField('Phone Number',[validators.NumberRange(min=30000000, max=99999999, message="Please enter a valid phone number")])
payment_mode = RadioField('Payment Mode',choices=cardlist, default='')
credit_card_number = IntegerField('Credit Card Number', [validators.NumberRange(min=3000000000000, max=9999999999999999,message="Please enter a valid Credit Card Number")])
credit_card_expiry = DateField('Credit Card Expiry Date', validators=[DateRange(min=date.today(), format='%Y-%m-%d', message="Please choose a valid date")])
credit_card_cvv = IntegerField('CVV', [validators.NumberRange(min=100, max = 999, message="Please enter a valid CVV")])
street_name = StringField('Street Name',[validators.DataRequired()])
postal_code = DecimalField('Postal Code', [validators.NumberRange(min=10000, max=830000, message="Postal code is 6 digits")])
unit_no = StringField('Unit No',[validators.Length(min=5,max=7,message="Please enter a valid unit number"),validators.DataRequired()])
class CollectionForm(Form):
name = StringField('Cardholder Name',[validators.DataRequired()])
phone = IntegerField('Phone Number',[validators.DataRequired(), validators.NumberRange(min=30000000, max=99999999, message="Please enter a valid phone number")])
payment_mode = RadioField('Payment Mode',choices=cardlist, default='')
credit_card_number = IntegerField('Credit Card Number', [validators.DataRequired(), validators.NumberRange(min=3000000000000, max=9999999999999999,message="Please enter a valid Credit Card Number")])
credit_card_expiry = DateField('Credit Card Expiry Date', format = "%Y-%m-%d")
credit_card_cvv = IntegerField('CVV', [validators.DataRequired(), validators.NumberRange(min=100, max = 999)])
date = DateField('Date',validators = [DateRange(min = date.today(), format = '%Y-%m-%d', message="Please choose a valid date")])
time = TimeField('Time')
agendaChoices = [('products', 'Products'),
('delivery', 'Delivery'),
('app', 'Application'),
('customer', 'Customer')]
ratingChoice = [('1', '1'),
('2', '2'),
('3', '3'),
('4', '4'),
('5', '5')]
class FeedbackForm(Form):
name = StringField("Name:", [validators.DataRequired()], render_kw={"placeholder": "e.g. Lim Joo Seng"})
agenda = SelectField('What is your agenda?', choices= agendaChoices, default= "products")
comment = TextAreaField('Add a comment :)', [validators.DataRequired()], render_kw={"rows": 5})
rating = RadioField('', [validators.DataRequired()], choices= ratingChoice)
class SearchBar(Form):
search_input = StringField('')
admin_searchList = [('name-brand', 'Name/Brand')
, ('sub-category', 'Sub-Category')
, ('serial-no', 'Serial No.')]
class AdminSearch(Form):
search_cat = SelectField('', choices=admin_searchList, default='name-brand')
search_input = StringField('', [validators.DataRequired()])
# search_subcat = SelectField('', choices=subCatList, default='Select')
class ExportTransaction(Form):
delivery = BooleanField('')
collection = BooleanField('')
completed = BooleanField('')
uncompleted = BooleanField('')
class DiscountForm(Form):
discount_code = StringField('Discount code')
class AddDiscountAmountForm(Form):
discount_code = StringField('Discount code')
discount_condition = DecimalField('Price at which disount is applicable', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')], places=2)
discount_start = DateField('Date start', format = "%Y-%m-%d")
discount_expiry = DateField('Date expiry', format = "%Y-%m-%d")
discount_amount = DecimalField('Discount Amount', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')], places=2)
def validate_expiry_field(form, field):
if field.data < form.discount_start.data:
raise ValidationError("End date must not be earlier than start date.")
class AddDiscountPercentageForm(Form):
discount_code = StringField('Discount code')
discount_condition = DecimalField('Price at which disount is applicable', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')], places=2)
# discount_expiry = DateField('Expiry Date', format = "%Y-%m-%d")
discount_start = DateField('Date start', format = "%Y-%m-%d")
discount_expiry = DateField('Date expiry', format = "%Y-%m-%d")
discount_percentage = DecimalField('Discount Percentage', [validators.DataRequired(message='This is a required field.')
, validators.NumberRange(min=0, message='Value has to be more than 0')], places=2)