-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.py
executable file
·526 lines (480 loc) · 20.9 KB
/
routes.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
from flask import render_template, request, redirect, url_for, abort
from server import app, system
from src.drink_error_handling import check_drink_error, Drink_error
from src.side_error_handling import check_side_error, Side_error
from src.main_error_handling import MainError, check_main_error
'''
Dedicated page for "page not found"
'''
@app.route('/404')
@app.errorhandler(404)
def page_not_found(e=None):
return render_template('404.html'), 404
#home page that shows options for customer, inv or service
#this is going to be changed to show jut info for customer and then
#a new rroute for inv and service ill add alter
@app.route('/', methods=["GET", "POST"])
def home():
return render_template('home.html')
@app.route('/staff', methods=["GET", "POST"])
def staff():
if request.method == "POST":
if "Inventory" in request.form:
return redirect(url_for('inventory'))
if "Service" in request.form:
return redirect(url_for('current_orders'))
return render_template('staff.html')
@app.route('/staff/current_orders', methods=["GET", "POST"])
def current_orders():
order = system.order_id # order dictionary
if request.method == "POST":
#its a copy so that it doesnt give an error that size was changed
#during iteration
for x in order.copy():
if 'Complete Order {}'.format(
x) in request.form and request.form.get(
'Complete Order {}'.format(x)) != '':
# if complete is clicked then it changes status to "finished"
system.change_order_status(int(x), "Finished")
elif 'Picked up! {}'.format(
x) in request.form and request.form.get(
'Picked up! {}'.format(x)) != '':
system.delete_order(x)
return render_template('current_orders.html', order_id=system.order_id)
#this checks to see if u select adding any item or if u
#check the order which basically sends u to a confirm page
@app.route('/customer', methods=["GET", "POST"])
def customer():
if request.method == "POST":
#takes u to relevant page based on button
if 'ADD SIDE' in request.form:
return redirect(url_for("add_side"))
elif 'ADD MAIN' in request.form:
return redirect(url_for("add_main"))
elif 'ADD DRINK' in request.form:
return redirect(url_for("add_drink"))
elif 'CHECK ORDER' in request.form:
return redirect(url_for("check_order"))
price = 0
for drink in system.drink:
price += int(drink.get_price())
for main in system.main:
price += int(main.get_price())
for side in system.side:
price += int(side.get_price())
return render_template('order.html',
drink=system.drink,
main=system.main,
side=system.side,
price=price)
#this is the order checking page and will do the final check and get customer naame
# to create the actual order then send to the confirmation page, or print out errors
@app.route('/customer/complete_order', methods=["GET", "POST"])
def check_order():
errors = []
order_id = 0
if request.method == "POST":
#checks if u input customer name, then makes the order or returns and error
if "customer" in request.form:
customer = request.form["customer"]
if customer == '':
errors.append("Enter customer name")
elif "CONFIRM ORDER" in request.form:
order_id = system.create_order(customer, system.main,
system.side, system.drink)
if isinstance(order_id, list):
for x in order_id:
errors.append(x)
else:
return redirect(
url_for('completed_order', order_id=order_id))
else:
pass
if "CONFIRM ORDER" in request.form and "customer" not in request.form:
pass
price = 0
for drink in system.drink:
price += drink.get_price()
for main in system.main:
price += main.get_price()
for side in system.side:
price += side.get_price()
return render_template('check_order.html',
drink=system.drink,
main=system.main,
side=system.side,
price=price,
errors=errors)
#this is basically the confirmation page which changes route based on their
#order id so there ar emultiple pages for multiple orders
@app.route('/customer/completed_order/<order_id>', methods=["GET", "POST"])
def completed_order(order_id):
order_id = int(order_id)
order_content = system.get_order_from_order_ID(order_id)
if order_content == "No order for that ID":
return render_template('404.html')
status = order_content.status
mains = order_content.mains
sides = order_content.sides
drinks = order_content.drinks
customer = order_content.customer
price = order_content.get_price()
return render_template("completed_order.html",order_id = order_id,
customer=customer,
status=status,
mains=mains,
drinks=drinks,
sides=sides,
price=price)
#this takes u to a page where u can press three buttons to customise the main
#or select premade burgers or wraps
@app.route('/customer/add_main', methods=["GET", "POST"])
def add_main():
if request.method == "POST":
if "Customise" in request.form:
return redirect(url_for("add_main_custom"))
elif "Buy Base Burger" in request.form:
Beef = system.get_item_from_inv("Beef", "single")
Muffin_Bun = system.get_item_from_inv("Muffin Bun", "single")
mayo = system.get_item_from_inv("Mayonnaise", "single")
lettuce = system.get_item_from_inv("Lettuce", "single leaf")
system.create_main("Burger", Beef, 1, Muffin_Bun, 2,
[mayo, lettuce])
return redirect(url_for("customer"))
elif "Buy Base Wrap" in request.form:
Beef = system.get_item_from_inv("Beef", "single")
Tortilla = system.get_item_from_inv("Tortilla", "single")
mayo = system.get_item_from_inv("Mayonnaise", "single")
lettuce = system.get_item_from_inv("Lettuce", "single leaf")
system.create_main("Wrap", Beef, 1, Tortilla, 1, [mayo, lettuce])
return redirect(url_for("customer"))
else:
pass
return render_template("add_main.html")
#this is the custom burger page, it gets all the info and makes sure
#its its put into the right format to be entered into the python class
# it also saves values and errors to be printed out at the end if there are
# any errors.
@app.route('/customer/add_main_custom', methods=["GET", "POST"])
def add_main_custom():
values = {}
inv = system.inv
ingredient = []
errors = []
bun_wrap_num = 0
meat_num = 0
if request.method == "POST":
#gets every single field or makes the field = none or 0
#saves every value in a dict to be displayed on page refresh
#gets item from inventory, if it an item_type identifier
if "burger_or_wrap" in request.form:
burger_or_wrap = request.form['burger_or_wrap']
values["burger_or_wrap"] = burger_or_wrap
if burger_or_wrap == '':
errors.append("Please select a burger or a wrap")
else:
burger_or_wrap = None
errors.append("Please select a burger or a wrap")
if "bun_wrap_type" in request.form:
bun_wrap_type = request.form['bun_wrap_type']
values["bun_wrap_type"] = bun_wrap_type
bun_wrap = system.get_item_from_inv(bun_wrap_type, "single")
if bun_wrap_type == '':
errors.append("Please select a bun or a wrap")
else:
bun_wrap = None
errors.append("Please select a bun or a wrap")
for x in inv.inventory:
if "bun_wrap_num{}".format(
x.name) in request.form and request.form.get(
"bun_wrap_num{}".format(
x.name)) != '' and x.name == bun_wrap_type:
bun_wrap_num = request.form['bun_wrap_num{}'.format(x.name)]
values["bun_wrap_num"] = bun_wrap_num
if "meat_filling" in request.form:
meat_filling = request.form['meat_filling']
values["meat_filling"] = meat_filling
#get from inv example
meat = system.get_item_from_inv(meat_filling, "single")
else:
meat = None
meat_filling = None
meat_num = None
for x in inv.inventory:
if "meat_num{}".format(
x.name) in request.form and request.form.get(
"meat_num{}".format(
x.name)) != '' and x.name == meat_filling:
meat_num = request.form['meat_num{}'.format(x.name)]
values["meat_num{}".format(x.name)] = meat_num
meat_num = int(meat_num)
if not isinstance(meat_num, int):
for x in inv.inventory:
if "meat_num{}".format(
x.name) in request.form and request.form.get(
"meat_num{}".format(x.name)) != '':
values["meat_num{}".format(
x.name)] = request.form['meat_num{}'.format(x.name)]
meat_num = request.form['meat_num{}'.format(x.name)]
meat_num = int(meat_num)
for x in inv.inventory:
if '{}{}'.format(
x.name, x.unit_of_measurement
) in request.form and request.form.get('{}{}'.format(
x.name, x.unit_of_measurement)) != "":
item = system.get_item_from_inv(x.name, x.unit_of_measurement)
ingredient.append(item)
values[x.name] = x.name
#once you have appropriate inputs, you sort to see if they are none,
# dont add them to ingredients and then check to see if they are None not to input
# as it will break.
#making meat num == 0 as inputing meat_filling as none crashes the program
#this way tis caught in error handling and not output at all
if meat == None:
if meat_num != None:
errors.append("Please select a meat type for your number")
meat_num = 0
meat = system.get_item_from_inv("Beef", "single")
if meat_num == None:
if meat != None:
errors.append("Please select anumber for your meat type")
meat_num = 0
check = check_main_error(burger_or_wrap, meat, int(meat_num), bun_wrap,
int(bun_wrap_num), ingredient)
#makes main and returns errors if there is an error or redirects
# back to customer to add more items or complete order
if check != []:
for x in check:
errors.append(x)
elif errors != []:
pass
else:
inv1 = system.check_if_enough_item_quantity_in_inv(meat, int(meat_num))
inv2 = system.check_if_enough_item_quantity_in_inv(bun_wrap, int(bun_wrap_num))
if inv1 == False:
errors.append("Not enough {} in inv".format(meat))
if inv2 == False:
errors.append("Not enough {} in inv".format(bun_wrap))
for x in ingredient:
inv = system.check_if_enough_item_quantity_in_inv(x,1)
if inv == False:
errors.append("Not enough {} in inv".format(x))
break
if errors == []:
system.create_main(burger_or_wrap, meat,
int(meat_num), bun_wrap,
int(bun_wrap_num), ingredient)
return redirect(url_for('customer'))
return render_template("add_main_custom.html",
errors=errors,
values=values,
inv=system.inv)
#this does the exact same thing as main but for sides and there are more options to filter from,
#also the side number is a multiplication of the size (2 scoops) by the amount they want (2 sundaes)
@app.route('/customer/add_side', methods=["GET", "POST"])
def add_side():
errors = []
error = False
redir = False
values = {}
inv = system.inv
create = {}
something = False
if request.method == "POST":
#(request.form)
for x in inv.inventory:
if 'BUY {} of {} size'.format(
x.name, x.unit_of_measurement
) in request.form and request.form.get('BUY {} of {} size'.format(
x.name, x.unit_of_measurement)) != "":
values['BUY {} of {} size'.format(
x.name, x.unit_of_measurement)] = request.form.get(
'BUY {} of {} size'.format(x.name,
x.unit_of_measurement))
if 'BUY {} of {} num'.format(
x.name, x.unit_of_measurement
) in request.form and request.form.get(
'BUY {} of {} num'.format(
x.name, x.unit_of_measurement)) != "":
values['BUY {} of {} num'.format(
x.name, x.unit_of_measurement)] = request.form.get(
'BUY {} of {} num'.format(x.name,
x.unit_of_measurement))
something = True
val = request.form.get('BUY {} of {} size'.format(
x.name, x.unit_of_measurement))
num = int(
request.form.get('BUY {} of {} num'.format(
x.name, x.unit_of_measurement)))
#if its a single unit, therefore small multiply buy certain alrge values
#otherwise multiple by smaller values
#i.e fries multiply by 25 singles for a small or
#for sundae multiply by 1 scoop for small
if val == "small" and x.unit_of_measurement == "single":
val = 25
elif val == "medium" and x.unit_of_measurement == "single":
val = 35
elif val == "large" and x.unit_of_measurement == "single":
val = 50
elif val == "small":
val = 1
elif val == "medium":
val = 2
elif val == "large":
val = 3
else:
val = 0
num = num * val
create[x] = num
else:
error = True
errors.append("Enter a value for your selection")
elif 'BUY {} of {} num'.format(
x.name, x.unit_of_measurement
) in request.form and request.form.get('BUY {} of {} num'.format(
x.name, x.unit_of_measurement)) != "":
values['BUY {} of {} num'.format(
x.name, x.unit_of_measurement)] = request.form.get(
'BUY {} of {} num'.format(x.name,
x.unit_of_measurement))
errors.append("Please select a size for the side")
error = True
else:
pass
for x, y in create.items():
side = check_side_error(x, y)
check = system.check_if_enough_item_quantity_in_inv(x, y)
if side != []:
error = True
for z in side:
errors.append(z)
elif check == False:
error = True
errors.append('Not enough in inventory for {}'.format(x))
else:
redir = True
if request.method == "POST" and something == False and values == {} and create == {}:
error = True
errors.append("Please select something or leave the page")
if redir == True and error == False:
for x, y in create.items():
system.create_side(x, y)
return redirect(url_for("customer"))
return render_template("add_side.html",
errors=errors,
values=values,
inv=system.inv)
#same as side
@app.route('/customer/add_drink', methods=["GET", "POST"])
def add_drink():
errors = []
error = False
redir = False
values = {}
create = {}
inv = system.inv
something = False
if request.method == "POST":
for x in inv.inventory:
if 'BUY {} of {}'.format(
x.name, x.unit_of_measurement
) in request.form and request.form.get('BUY {} of {}'.format(
x.name, x.unit_of_measurement)) != "":
something = True
val = int(
request.form.get('BUY {} of {}'.format(
x.name, x.unit_of_measurement)))
values['BUY {} of {}'.format(x.name,
x.unit_of_measurement)] = val
create[x] = val
else:
pass
#x is the item and y is the vlaue needed to be made
for x, y in create.items():
drink = check_drink_error(x, y)
check = system.check_if_enough_item_quantity_in_inv(x, y)
if drink != []:
error = True
for error in drink:
errors.append(error)
elif check == False:
error = True
errors.append('Not enough in inventory for {}'.format(x))
else:
redir = True
if something == False:
error = True
errors.append("Please select something or leave the page")
if redir == True and error == False:
for x, y in create.items():
system.create_drink(x, y)
return redirect(url_for("customer"))
return render_template("add_drink.html",
errors=errors,
values=values,
inv=system.inv)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INVENTORY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@app.route('/staff/inventory', methods=["GET", "POST"])
def inventory():
inv = system.inv
if request.method == "POST":
for x in inv.inventory:
if 'EDIT {}'.format(x.name) in request.form and request.form.get(
'EDIT {}'.format(x.name)) != "":
val = int(request.form.get('EDIT {}'.format(x.name)))
if val > 0:
inv.add_item_quantity(x, val)
else:
inv.reduce_item(x, -val)
else:
pass
if 'CREATE ITEM' in request.form:
return redirect(url_for("create_item"))
elif 'REMOVE ITEM' in request.form:
return redirect(url_for("remove_item"))
return render_template("inventory.html", inv=system.inv)
@app.route('/staff/inventory/create_item', methods=["GET", "POST"])
def create_item():
values = {}
if request.method == "POST":
# name
name = request.form.get('name')
if name == '':
pass
# units
if "Units" in request.form:
units = request.form['Units']
values["Units"] = units
else:
units = None
#price
price = request.form.get('Price')
price = int(price)
# type
if "Type" in request.form:
type_of = request.form["Type"]
values["Type"] = type_of
else:
type_of = None
# quantity
quantity = (request.form.get("Quantity"))
if quantity == "":
quantity = 0
else:
quantity = int(quantity)
new_item = system.inv.create_item(name, price, units, type_of)
system.inv.add_item_quantity(new_item, quantity)
return render_template("create_item.html", values=values)
@app.route('/staff/inventory/remove_item', methods=["GET", "POST"])
def remove_item():
inv = system.inv
if request.method == "POST":
delete = []
for x in inv.inventory:
if request.form.get('REMOVE {}'.format(x.name)) != None:
delete.append(x)
else:
pass
for item in delete:
inv.remove_item(item)
return render_template("remove_item.html", inv=system.inv)