-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.py
180 lines (164 loc) · 5.37 KB
/
menu.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
import auth
import database as db
from helper import assert_type, clear_terminal, print_sep
from notifications import show_reminders
from todo_list import add_list, display_lists, fetch_list, list_view, remove_list
def menu(user, database):
if user["role"] == "user":
user_menu(user, database)
elif user["role"] == "admin":
admin(user, database)
# admin should be able to:
# add,edit and remove users.
# add,edit and remove lists of other users
# add,edit and remove tasks of other users
# give/remove access of lists to specific users
def admin(user, database):
# welcome message
print("ADMIN PANEL")
print(f'welcome {user["username"]}')
# fetch all the lists in system
lists = fetch_list(database, user)
while True:
# print options
print(
"1. display lists \n2. add list \n3. select list \n4. remove list \n5. add user \n6. remove user \n7. edit user \n8. view users \n9. exit \n10. logout and exit"
)
# get user choice
ch = input("Enter choice: ")
clear_terminal()
# display lists
if ch == "1":
if len(lists) == 0:
print("Empty!")
else:
display_lists(lists)
# add list
elif ch == "2":
lists.append(add_list(database, user))
# select list
elif ch == "3":
if display_lists(lists):
ch = assert_type(
input("Enter Choice: "),
int,
"Enter Choice: ",
"Please enter an integer!",
True,
key=lambda x: True if x <= len(lists) and x > 0 else False,
)
if ch:
ch -= 1
list_view(lists[ch], user)
# remove list
elif ch == "4":
if display_lists(lists):
ch = assert_type(
input("Enter Choice: "),
int,
"Enter Choice: ",
"Please enter an integer!",
True,
key=lambda x: True if x <= len(lists) and x > 0 else False,
)
if ch:
ch -= 1
remove_list(database, lists[ch])
# add user
elif ch == "5":
auth.add_user(database, False)
# remove user
elif ch == "6":
auth.remove_user(database)
# edit user
elif ch == "7":
auth.edit_user(database)
# view users
elif ch == "8":
print_sep("Users")
print_sep()
for i, user in enumerate(database["users"]):
print(f"{i+1}. {user}")
print_sep()
# exit
elif ch == "9":
break
# logout and exit
elif ch == "10":
database["user"] = None
break
# invalid input
else:
print("invalid input!")
# user should be able to:
# add,edit and remove lists
# add,edit and remove tasks
# give/remove access of lists to others if the person is the owner
def user_menu(user, database):
# welcome message
print(f'Welcome {user["username"]}!')
# fetch lists which the user owns or has access to
lists = fetch_list(database, user)
tasks = []
for task_list in lists:
tasks.extend(task_list["tasks"])
show_reminders(tasks)
while True:
# print options
print(
"1. display lists \n2. add list \n3. select list \n4. remove list \n5. edit credentials \n6. exit \n7. logout and exit"
)
# get user choice
ch = input("Enter choice: ")
clear_terminal()
# display lists
if ch == "1":
display_lists(lists)
# add list
elif ch == "2":
database["lists"].append(add_list(database, user))
lists = fetch_list(database=database, user=user)
# edit list view
elif ch == "3":
if display_lists(lists):
ch = assert_type(
input("Enter Choice: "),
int,
"Enter Choice: ",
"Please enter an integer!",
True,
key=lambda x: True if x <= len(lists) and x > 0 else False,
)
if ch:
ch -= 1
list_view(lists[ch], user)
clear_terminal()
# remove list
elif ch == "4":
if display_lists(lists):
ch = assert_type(
input("Enter Choice: "),
int,
"Enter Choice: ",
"Please enter an integer!",
True,
key=lambda x: True if x <= len(lists) and x > 0 else False,
)
if ch:
ch -= 1
remove_list(database, lists[ch])
# edit credentials
elif ch == "5":
user = auth.edit_user(database, user["username"])
if database["user"]:
database["user"] = user["username"]
# exit
elif ch == "6":
break
# logout and exit
elif ch == "7":
database["user"] = None
break
# invalid input
else:
print("invalid input!")