/
helpers.py
103 lines (83 loc) · 2.26 KB
/
helpers.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
from sqlalchemy import create_engine, engine
from sqlalchemy.orm import session, sessionmaker
from database_setup import Base, Restaurant, MenuItem
import cgi
engine = create_engine("sqlite:///restaurantmenu.db")
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Restaurant's Methods
def addRestaurant(resturantName):
"""
Adds a new Restaurant to the database.
"""
temp = Restaurant(name=resturantName)
session.add(temp)
session.commit()
def printRestaurant():
"""
Prints all the Restaurant Name
from the Restaurant table.
"""
items = session.query(Restaurant).all()
if items:
for item in items:
print(item.name)
else:
print("Restaurants Not Found")
def getRestaurant():
"""
Returns a List of all Restaurant Names
"""
items = session.query(Restaurant).all()
if items:
l = []
for item in items:
l.append(item.name)
return l
else:
return []
def deleteRestaurant(RestaurantName):
temp = session.query(Restaurant).filter_by(name=RestaurantName).one()
print(temp.name, "is being DELETED...")
session.delete(temp)
session.commit()
print("Deleted Sucessfully")
def findRestaurant(RestaurantName):
"""
Checks whether the Restaurant
is present in the Database or not.
If not present then message is printed
else the list of Restaurants will be printed.
"""
temp = session.query(Restaurant).filter_by(name=RestaurantName).all()
if not temp:
print("Restaurant Not Found")
else:
for item in temp:
print(item.name)
# Menu Item Methods
def addMenuItem(
name=None, id=None, course=None, description=None, price=None, restaurant_id=None
):
"""
Adds a new Menu Item to the Database,
each item is associated with a restaurant.
"""
temp = MenuItem(
name=name,
description=description,
course=course,
price=price,
restaurant_id=restaurant_id,
)
session.add(temp)
session.commit()
def printDishes():
"""
Prints all the available dishes
from the MenuItem Table
"""
items = session.query(MenuItem).all()
for item in items:
print(item.name)