Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprocessorder1.cgi
More file actions
Latest commit
executable file
·64 lines (54 loc) · 1.98 KB
/
Copy pathprocessorder1.cgi
File metadata and controls
executable file
·64 lines (54 loc) · 1.98 KB
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
#!/usr/local/bin/python3
importcgi
frompizza_kitchen_helpersimport*
defprocess_form(form_data):
num_pizzas=int(form_data.getvalue("pizza"))
returnnum_pizzas
defget_available_pizzas(db,cursor):
sql="select * from pizza"
cursor.execute(sql)
pizzas=cursor.fetchall()
returnpizzas
defget_available_sizes(db,cursor):
sql="select * from size"
cursor.execute(sql)
sizes=cursor.fetchall()
returnsizes
defcreate_pizza_drop_down(pizzas,name):
drop_down="""<select name="pizza{0}">""".format(name)
foreachinpizzas:
drop_down+="""<option value="{0}">{1}</option>""".format(each[0],each[1])
drop_down+="</select>"
returndrop_down
defcreate_size_drop_down(sizes,name):
drop_down="""<select name="size{0}">""".format(name)
foreachinsizes:
drop_down+="""<option value="{0}">{1}</option>""".format(each[0],each[0])
drop_down+="</select>"
returndrop_down
defcreate_form(num_pizzas,pizzas,sizes):
form="""<form method="post" action="processorder2.cgi"/>"""
foreachinrange(num_pizzas):
form+=create_pizza_drop_down(pizzas,each)
form+=create_size_drop_down(sizes,each)
form+="<br/>"
form+="""<input type="submit" name="submit" value="Summarise Order"/>"""
form+="""<input type="hidden" name="quantity" value="{0}"/>""".format(num_pizzas)
form+="</form>"
returnform
if__name__=="__main__":
try:
html_top("Select Pizzas")
form_data=cgi.FieldStorage()
num_pizzas=process_form(form_data)
db,cursor=connect_pizza_database()
pizzas=get_available_pizzas(db,cursor)
sizes=get_available_sizes(db,cursor)
form=create_form(num_pizzas,pizzas,sizes)
print("<h1>Pizza Kitchen</h1>")
print("<h2>Choose Pizza Types and Sizes</h2>")
print(form)
cursor.close()
html_tail()
except:
cgi.print_exception()