-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBMockUp.py
More file actions
46 lines (34 loc) · 1.13 KB
/
DBMockUp.py
File metadata and controls
46 lines (34 loc) · 1.13 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
import json
import pdb
class DBMockUp(object):
def __init__(self):
self.db_filename='./DB.json'
self.data=json.load(open(self.db_filename))
def update_db_file(self):
json.dump(self.data,open(self.db_filename,'w'),indent=4)
def get_meals(self):
return self.data['Meals']
def get_orders(self):
return self.data['Orders']
def get_name_of(self, field_name, sub_field_name, ID):
name = "NO NAME"
for m in self.data[field_name]:
if m['id']==ID:
name=m[sub_field_name]
break
return name
def set_order_buyer(self,ID,buyer):
found = [o for o in self.data['Orders'] if o['id']==int(ID)]
if len(found)==0:
return False
found[0]['buyer']=buyer
self.update_db_file()
return found[0]
def get_locations(self):
return self.data['Locations']
def create_order(self, order):
new_id = 1+max([o['id'] for o in self.get_orders()])
order['id']=new_id
self.data['Orders'].append(order)
self.update_db_file()
return order