Spaces:
Sleeping
Sleeping
File size: 3,482 Bytes
f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed 0b7c30e f7778ed |
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 |
import streamlit as st
from streamlit_option_menu import option_menu
import pymongo
class ErrorMSG:
ERROR_MSG_NONESTR = 0
ERROR_MSG_NOFOUND = 1
ERROR_MSG_NONESTREDIT = 2
msg = [
'Warning: You should input a Task above and select the right Category & Priority',
'Warning: No such task found, Please check your input agian',
'Warning: You should input a Task you want to edit and input the right information you want to edit'
]
uri = "mongodb+srv://123123:mb123123@cluster.c0bshep.mongodb.net/?retryWrites=true&w=majority"
client = pymongo.MongoClient(uri)
db = client["demo"]
collection = db["class"]
st.set_page_config(page_title="Marble's ToDo List",layout='wide')
st.title('TODO LIST')
st.write('This is a TODO List which allows you to insert, update, delete your task')
with st.sidebar:
page = option_menu("ToDo List",['Home','Insert','Edit', 'Delete'],
icons=['house','box-arrow-in-up','brush', 'backspace-reverse'])
if page == 'Insert':
st.header('Insert Task')
task = st.text_input('Task')
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
pri = st.slider('Priority', 1, 5)
if st.button('Insert'):
if len(task):
collection.insert_one({'Task': task, 'Category': cate, 'Priority': pri})
st.success('Successfully Inserted')
else:
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NONESTR], icon="⚠️")
elif page == 'Edit':
st.header('Edit Task')
task = st.text_input('Find the Task & Category & Priority you want to Edit')
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
pri = st.slider('Priority', 1, 5)
st.header('Input your Edit')
taskEdit = st.text_input('Input the Task & Category & Priority you want to Edit')
cateEdit = st.selectbox('Edit Category', ['Work', 'Study', 'Entertainment'])
priEdit = st.slider('Edit Priority', 1, 5)
if st.button('Edit'):
if len(task) and len(taskEdit):
result = collection.find_one({'Task': task, 'Category': cate, 'Priority': pri})
if (result):
collection.update_one({'Task': task, 'Category': cate, 'Priority': pri}, {'$set':{'Task': taskEdit, 'Category': cateEdit, 'Priority': priEdit}})
st.success('Successfully Edited')
else:
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NOFOUND], icon="⚠️")
else:
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NONESTREDIT], icon="⚠️")
elif page == 'Delete':
st.header('Delete Task')
task = st.text_input('Input the Task & Category you want to Delete')
cate = st.selectbox('Category', ['Work', 'Study', 'Entertainment'])
pri = st.slider('Priority', 1, 5)
if st.button('Delete'):
if (len(task)):
result = collection.find_one({'Task': task, 'Category': cate, 'Priority': pri})
if (result):
collection.delete_one({'Task': task, 'Category': cate, 'Priority': pri})
st.success('Successfully Deleted')
else:
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NOFOUND], icon="⚠️")
else:
st.warning(ErrorMSG.msg[ErrorMSG.ERROR_MSG_NONESTR], icon="⚠️")
elif page == 'Home':
st.header('Home Page')
tasks = collection.find({}, {'_id':0, }).sort([('Priority', -1), ('Task', 1)])
st.table(tasks) |