-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
210 lines (165 loc) · 7.87 KB
/
Copy pathmain.py
File metadata and controls
210 lines (165 loc) · 7.87 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
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
import tasks
from categories import Categories, Category
import datetime
def main():
global task
tasklist = tasks.TaskList()
tl_categories = Categories()
# UI
while True:
print("\n\n===== To-Do List =====")
print("1. Add Task")
print("2. Show Tasks")
print("3. Edit Tasks")
print("4. Categories related actions")
print("5. Exit")
choice = input("\nEnter your choice: ")
if not choice.isdigit():
print("\nInvalid input. Enter a number!\n")
continue
if choice == '1':
tasklist.add_task(tl_categories)
elif choice == '2':
tasklist.show_tasks()
elif choice == '3':
if not tasklist.tasks:
print("No tasks to edit!")
continue
while True:
print("\n\n=== Which task do you want to edit? ===")
for number, task in enumerate(tasklist.tasks, start=1):
print(f"{number}. {task.name}")
edit_choice = input('\nEnter task number (or "exit" to exit editing): ')
if edit_choice == 'exit':
break
if not edit_choice.isdigit():
print("\nInvalid input. Enter a number!\n")
continue
if int(edit_choice) > len(tasklist.tasks):
print("\nInvalid input. No such task!\n")
continue
task_to_edit = tasklist.tasks[int(edit_choice) - 1]
while True:
print("\n\n== What do you want to edit? ==")
print("1. Name")
print("2. Category")
print("3. Importance")
print("4. Completion")
print("5. Delete This Task")
print("6. Exit")
edit_type_choice = input('\nEnter your choice: ')
if not edit_type_choice.isdigit():
print("\nInvalid input. Enter a number!\n")
continue
if edit_type_choice == '1':
task_to_edit.change_name()
break
elif edit_type_choice == '2':
if not tl_categories.categories:
print("\nNo categories exist! Add one first.")
else:
task_to_edit.change_category(tl_categories.categories)
break
elif edit_type_choice == '3':
task_to_edit.change_importance()
break
elif edit_type_choice == '4':
task_to_edit.change_completion()
break
elif edit_type_choice == '5':
delete_choice = input("\nAre you sure you want to delete this task? (Y/N): ")
if delete_choice.upper() == 'Y':
tasklist.tasks.pop(int(edit_choice) - 1)
print("Task deleted!")
elif delete_choice.upper() == 'N':
print("Task won't be deleted!")
pass
else:
print("\nInvalid input. Please try again.\n")
break
elif edit_type_choice == '6':
break
break
elif choice == '4':
print("\n\n=== What categories related actions do you want to do? ===")
print("1. Add Category")
print("2. Show Categories")
print("3. Edit Category")
print("4. Delete Category")
print("5. Exit")
choice = input("\nEnter your choice: ")
while True:
if not choice.isdigit():
print("\nInvalid input. Enter a number!\n")
continue
if choice == '1':
tl_categories.add_category()
break
if choice == '2':
tl_categories.show_categories()
break
if choice == '3':
print("\n\n=== Which category do you want to edit? ===")
tl_categories.categories.enum_categories()
edit_choice = input('\nEnter category number (or "exit" to exit editing): ')
if str(edit_choice) == 'exit':
break
if not edit_choice.isdigit():
print("\nInvalid input. Enter a number!\n")
continue
if int(edit_choice) > len(tl_categories.categories):
print("\nInvalid input. No such task!\n")
continue
category_to_edit = tl_categories.categories[int(edit_choice) - 1]
category_to_edit.change_name()
break
elif choice == '4':
print("\n\n=== Which category do you want to edit? ===")
tl_categories.categories.enum_categories()
edit_choice = input('\nEnter category number (or "exit" to exit editing): ')
if str(edit_choice) == 'exit':
break
if not edit_choice.isdigit():
print("\nInvalid input. Enter a number!\n")
continue
if int(edit_choice) > len(tl_categories.categories):
print("\nInvalid input. No such task!\n")
continue
else:
delete_choice = input("\nAre you sure you want to delete this category? (Y/N): ")
if delete_choice.upper() == 'Y':
tl_categories.categories.pop(int(edit_choice) - 1)
print("Task deleted!")
elif delete_choice.upper() == 'N':
print("Task won't be deleted!")
pass
else:
print("\nInvalid input. Please try again.\n")
break
elif choice == '5':
break
elif choice == '5':
break
# admin action automatically adds 6 tasks and 2 categories for testing
elif choice == '6':
password = input("\nEnter password: ")
if password == 'admin539':
category1 = Category('Work')
category2 = Category('School')
tl_categories.categories.append(category1)
tl_categories.categories.append(category2)
task1 = tasks.Task('Task1', 'HIGH', datetime.date.today(), category1)
task2 = tasks.Task('Task2', 'MEDIUM', datetime.date.today(), category1)
task3 = tasks.Task('Task3', 'LOW', datetime.date.today(), category1)
task4 = tasks.Task('Task4', 'HIGH', datetime.date.today(), category2)
task5 = tasks.Task('Task5', 'MEDIUM', datetime.date.today(), category2)
task6 = tasks.Task('Task6', 'LOW', datetime.date.today(), category2)
admin_tasks = [task1, task2, task3, task4, task5, task6]
for task in admin_tasks:
tasklist.tasks.append(task)
else:
print("\nInvalid password. You're not an admin!\n")
else:
print("\nInvalid input. Try again!\n")
if __name__ == "__main__":
main()