Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +54 -7
- requirements.txt +0 -0
app.py
CHANGED
@@ -1,39 +1,86 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import pymongo
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
uri = "mongodb+srv://123123:mb123123@cluster.c0bshep.mongodb.net/?retryWrites=true&w=majority"
|
5 |
|
6 |
client = pymongo.MongoClient(uri)
|
7 |
db = client["demo"]
|
8 |
collection = db["class"]
|
9 |
|
|
|
|
|
10 |
st.title('TODO LIST')
|
11 |
st.write('This is a TODO List which allows you to insert, update, delete your task')
|
12 |
|
13 |
-
|
|
|
|
|
14 |
|
15 |
if page == 'Insert':
|
16 |
st.header('Insert Task')
|
17 |
task = st.text_input('Task')
|
18 |
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
|
|
|
19 |
|
20 |
if st.button('Insert'):
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
23 |
|
24 |
elif page == 'Edit':
|
25 |
st.header('Edit Task')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
elif page == 'Delete':
|
28 |
st.header('Delete Task')
|
29 |
-
task = st.text_input('Input the Task&Category you want to
|
30 |
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
|
|
|
31 |
|
32 |
if st.button('Delete'):
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
elif page == 'Home':
|
37 |
st.header('Home Page')
|
38 |
-
tasks = collection.find({}, {'_id':0, })
|
39 |
st.table(tasks)
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit_option_menu import option_menu
|
3 |
import pymongo
|
4 |
|
5 |
+
class ErrorMSG:
|
6 |
+
ERROR_MSG_NONESTR = 0
|
7 |
+
ERROR_MSG_NOFOUND = 1
|
8 |
+
ERROR_MSG_NONESTREDIT = 2
|
9 |
+
|
10 |
+
msg = [
|
11 |
+
'Warning: You should input a Task above and select the right Category & Priority',
|
12 |
+
'Warning: No such task found, Please check your input agian',
|
13 |
+
'Warning: You should input a Task you want to edit and input the right information you want to edit'
|
14 |
+
]
|
15 |
+
|
16 |
uri = "mongodb+srv://123123:mb123123@cluster.c0bshep.mongodb.net/?retryWrites=true&w=majority"
|
17 |
|
18 |
client = pymongo.MongoClient(uri)
|
19 |
db = client["demo"]
|
20 |
collection = db["class"]
|
21 |
|
22 |
+
st.set_page_config(page_title="Marble's ToDo List",layout='wide')
|
23 |
+
|
24 |
st.title('TODO LIST')
|
25 |
st.write('This is a TODO List which allows you to insert, update, delete your task')
|
26 |
|
27 |
+
with st.sidebar:
|
28 |
+
page = option_menu("ToDo List",['Home','Insert','Edit', 'Delete'],
|
29 |
+
icons=['house','box-arrow-in-up','brush', 'backspace-reverse'])
|
30 |
|
31 |
if page == 'Insert':
|
32 |
st.header('Insert Task')
|
33 |
task = st.text_input('Task')
|
34 |
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
|
35 |
+
pri = st.slider('Priority', 1, 5)
|
36 |
|
37 |
if st.button('Insert'):
|
38 |
+
if len(task):
|
39 |
+
collection.insert_one({'Task': task, 'Category': cate, 'Priority': pri})
|
40 |
+
st.success('Successfully Inserted')
|
41 |
+
else:
|
42 |
+
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NONESTR], icon="⚠️")
|
43 |
|
44 |
elif page == 'Edit':
|
45 |
st.header('Edit Task')
|
46 |
+
task = st.text_input('Find the Task & Category & Priority you want to Edit')
|
47 |
+
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
|
48 |
+
pri = st.slider('Priority', 1, 5)
|
49 |
+
|
50 |
+
st.header('Input your Edit')
|
51 |
+
taskEdit = st.text_input('Input the Task & Category & Priority you want to Edit')
|
52 |
+
cateEdit = st.selectbox('Edit Category', ['Work', 'Study', 'Entertainment'])
|
53 |
+
priEdit = st.slider('Edit Priority', 1, 5)
|
54 |
+
|
55 |
+
if st.button('Edit'):
|
56 |
+
if len(task) and len(taskEdit):
|
57 |
+
result = collection.find_one({'Task': task, 'Category': cate, 'Priority': pri})
|
58 |
+
if (result):
|
59 |
+
collection.update_one({'Task': task, 'Category': cate, 'Priority': pri}, {'$set':{'Task': taskEdit, 'Category': cateEdit, 'Priority': priEdit}})
|
60 |
+
st.success('Successfully Edited')
|
61 |
+
else:
|
62 |
+
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NOFOUND], icon="⚠️")
|
63 |
+
else:
|
64 |
+
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NONESTREDIT], icon="⚠️")
|
65 |
|
66 |
elif page == 'Delete':
|
67 |
st.header('Delete Task')
|
68 |
+
task = st.text_input('Input the Task & Category you want to Delete')
|
69 |
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
|
70 |
+
pri = st.slider('Priority', 1, 5)
|
71 |
|
72 |
if st.button('Delete'):
|
73 |
+
if (len(task)):
|
74 |
+
result = collection.find_one({'Task': task, 'Category': cate, 'Priority': pri})
|
75 |
+
if (result):
|
76 |
+
collection.delete_one({'Task': task, 'Category': cate, 'Priority': pri})
|
77 |
+
st.success('Successfully Deleted')
|
78 |
+
else:
|
79 |
+
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NOFOUND], icon="⚠️")
|
80 |
+
else:
|
81 |
+
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NONESTR], icon="⚠️")
|
82 |
|
83 |
elif page == 'Home':
|
84 |
st.header('Home Page')
|
85 |
+
tasks = collection.find({}, {'_id':0, }).sort([('Priority', -1), ('Task', 1)])
|
86 |
st.table(tasks)
|
requirements.txt
CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
|
|