-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
549 lines (500 loc) · 21.2 KB
/
main.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
from InputHandling import InputHandler
from Person import Person
from construct_db import *
'''
Task Management System
-----------------------
Overall program intention:
This program is a task management system. It allows users to create, manage, and track tasks and projects.
Input and output info:
This program takes input through the cli and outputs info into the cli.
How the program is intended to be run:
Run this python file (main.py), and interact with the program using the cli
'''
class Current():
def __init__(self):
self.user = None
Session = sessionmaker(bind=engine)
self.session = Session()
def login(current: Current):
"""
This function allows user to login.
"""
print("/login\n")
login_username = InputHandler.Handler(current.session,
"Username inputted does not exist. Try again.\n",
"Please input your username below.\n"
"If you'd like to move to signup, input: SU\n"
"Username: ",
"login_username")
# if the return of login_username is "SU" it means user chose to sign up
# redirect to sign up
if login_username == "SU":
#signup()
return "SU"
else:
# validate user password by calling input handler
login_password = InputHandler.Handler(current.session,
"Password is incorrect. Try again.\n",
"Please input your password below.\n"
"If you'd like to move to signup, input: SU\n"
"Password: ",
"login_password",
login_username)
# user chose to sign up, redirect to sign up
if login_password == "SU":
#signup()
return "SU"
#sign up successfull, redirect to home
else:
current.user = Person(current.session, login_username, login_password, "login")
#home(user)
return "HOME"
def signup(current:Current):
'''
This function allows user to sign up.
'''
print("/signup\n")
signup_username = InputHandler.Handler(current.session,
"Your chosen username was invalid or taken, "
"make sure it confirms to the requirements below.\n",
"Please input your new username below.\n"
"Your username must be between 3-20 characters,\n"
"and must not have any special characters.\n"
"If you'd like to move to login, input: LI\n"
"Username: ",
"signup_username")
# user chose to login, redirect to login
if signup_username == "LI":
#login()
return "LI"
else:
# validate password
signup_password = InputHandler.Handler(current.session,
"Your password was invalid, "
"make sure it confirms to the requirements below.\n",
"Please input your new password below:\n"
"Your password must be between 8-30 characters.\n"
"You may use letters numbers, and these\n"
"special characters: -_.!@#$%^&*()\n"
"If you'd like to move to login, input: LI\n"
"Password: ",
"signup_password")
# user chose to login, redirect to login
if signup_password == "LI":
#login()
return "LI"
# user creation successful, redirect to home
else:
user = Person(current.session, signup_username, signup_password, "signup")
current.user = user
#home(new_user)
return "HOME"
def home(current: Current):
'''
This function displays the home menu, where the user can select what they want to do
Parameters:
user: Person object
'''
# display username
print("/home\n"
f"User: {current.user.username}\n")
# handler to select valid option of what user wants to do
navigation = InputHandler.Handler(current.session,
"Please input a valid input of 1, 2, 3, or 4 below.\n",
"Where would you like to navigate to:\n"
"1: Tasks\n"
"2: Projects\n"
"3: Notifications\n"
"4: Logout\n"
"Input: ",
"home_navigation"
)
# based on user input, call relevant function
match navigation:
case "1":
#tasks(user)
return "TASK"
case "2":
#projects(user)
return "PROJ"
case "3":
#notifications(user)
return "NOTIF"
case "4":
#main()
return "LO"
def notifications(current: Current):
'''
This function allows user to view notifications for project and task invitations
and accept or deny them.
Parameters:
user: Person object
'''
user = current.user
# get amount of notifications
num_notifs = user.notifications_length()
notifs = user.get_notifications()
# look through notifications until no notifications left
for i in range(num_notifs):
# retreive notification
current_notification = notifs[i]
# display notification
print(current_notification['message'])
# ask user if they accept or deny invitation, handler for valid input
project_task_acceptance = InputHandler.Handler(current.session,
"Please input a valid input of 1 or 2 below.\n",
"1: Accept\n"
"2: Decline\n",
"project_task_acceptance"
)
# if user accepts project invitation, add user to project
if project_task_acceptance == "1":
user.change_invitation_status(current_notification['id'], "accepted")
if current_notification['project']:
user.add_project_member(current_notification['item_id'])
print("test 1")
else:
user.add_task_member(current_notification['item_id'])
print("test 2")
else:
user.change_invitation_status(current_notification['id'], "declined")
print("test 3")
# print out message that all notifications are read
print(user.get_notifications())
# go to home screen
return "HOME"
def tasks(current: Current):
'''
This function displays the task navigation menu, where the user can select to
view tasks sorted by deadline or by priority, edit tasks, and create tasks.
Parameters:
user: Person object
'''
user = current.user
# handler to select valid option of what user wants to do
task_navigation = InputHandler.Handler(current.session,
"Please input a valid input of 1, 2, 3, 4, or 5 below.\n",
"Where within the tasks would you like to navigate:\n"
"1: View Tasks (storted by priority)\n"
"2: View Tasks (sorted by deadline)\n"
"3: Edit Task\n"
"4: Create Task\n"
"5: Back to Home\n"
"Input: ",
"task_navigation"
)
# basec on user choice, do action
match task_navigation:
# view tasks by priority
case "1":
user.view_tasks()
#tasks(user)
return "TASK"
# view tasks by deadline
case "2":
user.view_tasks()
#tasks(user)
return "TASK"
# edit tasks
case "3":
if user.tasks_length != 0:
user.view_tasks()
# user selects which task to edit
task_edit_navigation = InputHandler.Handler(current.session,
"Please input a valid input of a number below.\n",
"Which task would you like to edit:\n"
"Input B to go back.\n"
"Input: ",
"task_edit_navigation"
)
# go back to task page
match task_edit_navigation:
case "B":
#tasks(user)
return "TASK"
case _:
#tasks(user)
return "TASK"
else:
user.view_tasks()
#tasks(user)
return "TASK"
case "4":
# allow user to create a task
task_creation = InputHandler.Handler(current.session,
"Please input a valid input as shown below.\n",
"You must enter:\n"
"Task Name, Task Description, Task Project ID (0 if none),\n"
"Task Priority (1-7), and Task Deadline.\n"
"All must be sepearted by a comma.\n"
"Date must be in the form YYYY-MM-D\n"
"Example: Task1, A Task, 0, 1, 2023-12-12\n"
"Input B to go back.\n"
"Input: ",
"task_creation",
user
)
# based on user input, either task created successfully or no task created, go back to tasks page
match task_creation:
case "B":
#tasks(user)
return "TASK"
case _:
print("Task Created successfully\n")
#tasks(user)
return "TASK"
case "5":
#home(user)
return "HOME"
def projects(current: Current):
'''
This function displays the project navigation menu, where the user can select to
view projects, edit projects, and create projects.
Parameters:
user: Person object
'''
user = current.user
# handler to select valid option of what user wants to do
project_navigation = InputHandler.Handler(current.session,
"Please input a valid input of 1, 2, 3, or 4 below.\n",
"Where within the tasks would you like to navigate:\n"
"1: View Projects\n"
"2: Edit Project\n"
"3: Create Project\n"
"4: Back to Home\n"
"Input: ",
"project_navigation"
)
# basec on user choice, do action
match project_navigation:
# view projects
case "1":
user.view_projects()
#projects(user)
return "PROJ"
# edit projects
case "2":
if user.admin_projects_length() != 0:
user.view_projects()
# user chooses which project to edit
project_edit_navigation = InputHandler.Handler(current.session,
"Please input a valid input of a number below.\n",
"Which project would you like to edit:\n"
"Input B to go back.\n"
"Input: ",
"project_edit_navigation",
user
)
# go back to tasks page
match project_edit_navigation:
case "B":
#projects(user)
return "PROJ"
case _:
# user chooses how to edit the project
project_edit_navigation2 = InputHandler.Handler(current.session,
"Please input a valid input of 1, 2, 3, 4, 5, or 6 below.\n",
"What would you like to edit within the project:\n"
"1: Edit Project Name\n"
"2: Edit Project Description\n"
"3: Add Member\n"
"4: Remove Member\n"
"5: Delete Project\n"
"6: Back\n"
"Input: ",
"project_edit_navigation2"
)
match project_edit_navigation2:
case "1":
# user chooses a new name for the project
project_name_edit = InputHandler.Handler(current.session,
"Please input a valid input of a name below.\n",
"What would you like the new name of the project to be:\n"
"Input B to go back.\n"
"Input: ",
"project_name_edit"
)
# based on user input, either go back or update the name and go back
match project_name_edit:
case "B":
#projects(user)
return "PROJ"
case _:
user.change_project_name(int(project_edit_navigation), project_name_edit)
print("Project name successfully changed\n")
#projects(user)
return "PROJ"
case "2":
# user chooses a new description for the project
project_description_edit = InputHandler.Handler(current.session,
"Please input a valid input of a description below.\n",
"What would you like the new description of the project to be:\n"
"Input B to go back.\n"
"Input: ",
"project_description_edit"
)
# based on user input, either go back or update the description and go back
match project_description_edit:
case "B":
#projects(user)
return "PROJ"
case _:
user.change_project_description(int(project_edit_navigation), project_description_edit)
print("Project description successfully changed\n")
#projects(user)
return "PROJ"
case "3":
# user chooses a user to invite to the project
project_invite = InputHandler.Handler(current.session,
"Please input a valid input of a name below.\n",
"What user would you like to invite to the project:\n"
"Input B to go back.\n"
"Input: ",
"project_invite"
)
# based on user input, either go back or invite the user and go back
match project_invite:
case "B":
#projects(user)
return "PROJ"
case _:
user.invite_member(project_invite, int(project_edit_navigation))
#projects(user)
return "PROJ"
case "4":
# user chooses a user to remove from the project
project_remove = InputHandler.Handler(current.session,
"Please input a valid input of a name below.\n",
"What user would you like to remove from the project:\n"
"Input B to go back.\n"
"Input: ",
"project_remove"
)
# based on user input, either go back or remove the user and go back
match project_remove:
case "B":
#projects(user)
return "PROJ"
case _:
user.remove_project_member(project_remove, int(project_edit_navigation))
#projects(user)
return "PROJ"
case "5":
# user chooses to delete the project
project_delete = InputHandler.Handler(current.session,
"Please input the project name below.\n",
"Input the project name to delete the project:\n"
"Input B to go back.\n"
"Input: ",
"project_delete",
project_edit_navigation
)
# based on user input, either go back or delete the project
match project_delete:
case "B":
#projects(user)
return "PROJ"
case _:
user.delete_project(int(project_edit_navigation))
#projects(user)
return "PROJ"
case "6":
# go back
#projects(user)
return "PROJ"
else:
# if user is not admin to any project, they cannot edit any, sends user back
print("You are admin in no projects.\n")
#projects(user)
return "PROJ"
# create project
case "3":
project_creation = InputHandler.Handler(current.session,
"Please input a valid input as shown below.\n",
"You must enter:\n"
"Project Name and Project Description.\n"
"They must be sepearted by a comma.\n"
"Example: Project1, A Project\n"
"Input B to go back.\n"
"Input: ",
"project_creation",
user
)
# based on user input, either project created successfully or no task created, go back to tasks page
match project_creation:
case "B":
#projects(user)
return "PROJ"
case _:
print("Project Created successfully\n")
#projects(user)
return "PROJ"
# go home
case "4":
#home(user)
return "HOME"
def welcome(current: Current):
current.user = None
print("/index\n")
print("Welcome to Group 17's Task Management system!\n"
"To navigate, input the number cooresponding to\n"
"a possible output.\n")
# call input handler to obtain valid input
entry_method = InputHandler.Handler(current.session,
"Please input a valid input of 1 or 2 below.\n",
"Would you like to Login or Signup:\n"
"1: Login\n"
"2: Signup\n"
"3: Exit\n"
"Input: ",
"entry_method")
# based on user input, call relevant function
match entry_method:
# login
case "1":
return "LI"
# signup
case "2":
return "SU"
# user chose to exit
case "3":
return "EXIT"
def navigation(current):
exit = False
result = welcome(current)
# continue navigating
while not exit:
if result == "EXIT":
exit = True
elif result == "SU":
result = signup(current)
elif result == "LI":
result = login(current)
elif result == "LO":
result = welcome(current)
elif result == "HOME":
result = home(current)
elif result == "TASK":
result = tasks(current)
elif result == "PROJ":
result = projects(current)
elif result == "NOTIF":
result = notifications(current)
else:
print("error: invalid result in navigation()")
exit = True
if result == "EXIT":
print("Have a nice day!")
return result
#projects, tasks, notifications, home, login, signup
def main():
'''
This function is the starting point of the program. It allows the user to
log into their account or sign up as a new user.
'''
current = Current()
navigation(current)
current.session.close()
if __name__ == "__main__":
main()