-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadd_size.cgi
executable file
·63 lines (54 loc) · 1.84 KB
/
add_size.cgi
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
#!/usr/local/bin/python3
import cgi
from pizza_kitchen_helpers import *
def get_exisiting_sizes(db,cursor):
sql = "select * from size"
cursor.execute(sql)
sizes = cursor.fetchall()
return sizes
def create_size_form():
form = """
<form method="post" action="processsize.cgi">
<table>
<tr>
<th>Number of inches</th>
<th>Cost</th>
</tr>
<tr>
<td><input type="text" name="inches" placeholder="e.g. 12"/></td>
<td><input type="number" name="cost" min="1" max="6" step="0.1"/></td>
</tr>
</table>
<input type="submit" name="submit" value="Add new size"/>
</form>"""
return form
def create_existing_size_table(sizes):
if len(sizes) > 0:
table = """<table>
<tr>
<th>Number of inches</th>
<th>Cost</th>
</tr>"""
for existing in sizes:
row = """<tr>
<td>{0}</td>
<td>{1}</td>
</tr>""".format(existing[0],existing[1])
table += row
table += "</table>"
else:
table = "<p>There are currently no sizes in the database</p>"
return table
if __name__ == "__main__":
html_top("Add Sizes")
db,cursor = connect_pizza_database()
print("<h1>Pizza Kitchen</h1>")
print("<h2>Current Sizes</h2>")
current_sizes = get_exisiting_sizes(db,cursor)
size_table = create_existing_size_table(current_sizes)
print(size_table)
print("<h2>Add New Size</h2>")
new_form = create_size_form()
print(new_form)
html_tail()
cursor.close()