Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add the following functionality when the user selects vm to view all the tasks assigned to them: Display all tasks in a manner that is

Add the following functionality when the user selects vm to view all the tasks
assigned to them:
Display all tasks in a manner that is easy to read. Make sure that each
task is displayed with a corresponding number that can be used to
identify the task.
Allow the user to select either a specific task (by entering a number) or
input -1 to return to the main menu.
If the user selects a specific task, they should be able to choose to either
mark the task as complete or edit the task.
If the user chooses to mark a task as complete, the Yes/No
value that describes whether the task has been completed or not
should be changed to Yes.
4
if the user chooses to edit a task, the username of the person to
whom the task is assigned or the due date of the task can be
edited. The task can only be edited if it has not yet been
completed.
code -----------
# Notes:
# 1. Use the following username and password to access the admin rights
# username: admin
# password: password
# 2. Ensure you open the whole folder for this task in VS Code otherwise the
# program will look in your root directory for the text files.
#=====importing libraries===========
import os
from datetime import datetime, date
DATETIME_STRING_FORMAT ="%Y-%m-%d"
# Create tasks.txt if it doesn't exist
if not os.path.exists("tasks.txt"):
with open("tasks.txt","w") as default_file:
pass
with open("tasks.txt",'r') as task_file:
task_data = task_file.read().split("
")
task_data =[t for t in task_data if t !=""]
task_list =[]
for t_str in task_data:
curr_t ={}
# Split by semicolon and manually add each component
task_components = t_str.split(";")
curr_t['username']= task_components[0]
curr_t['title']= task_components[1]
curr_t['description']= task_components[2]
curr_t['due_date']= datetime.strptime(task_components[3], DATETIME_STRING_FORMAT)
curr_t['assigned_date']= datetime.strptime(task_components[4], DATETIME_STRING_FORMAT)
curr_t['completed']= True if task_components[5]== "Yes" else False
task_list.append(curr_t)
#====Login Section====
'''This code reads usernames and password from the user.txt file to
allow a user to login.
'''
# If no user.txt file, write one with a default account
if not os.path.exists("user.txt"):
with open("user.txt","w") as default_file:
default_file.write("admin;password")
# Read in user_data
with open("user.txt",'r') as user_file:
user_data = user_file.read().split("
")
# Convert to a dictionary
username_password ={}
for user in user_data:
username, password = user.split(';')
username_password[username]= password
logged_in = False
while not logged_in:
print("LOGIN")
curr_user = input("Username: ")
curr_pass = input("Password: ")
if curr_user not in username_password.keys():
print("User does not exist")
continue
elif username_password[curr_user]!= curr_pass:
print("Wrong password")
continue
else:
print("Login Successful!")
logged_in = True
# user defining for menu
def reg_user ():
new_username = input("Enter new Username: ").strip()
if new_username in username_password:
print("That username already exists please enter another one!")
else:
if new_username not in username_password:
while True:
new_password = input("Enter new Password: ").strip()
confirm_new_password = input("Re-enter new Password: ").strip()
if new_password == confirm_new_password:
print("New user added")
username_password[new_username]= new_password
with open("user.txt","w") as out_file:
user_data =[]
for k in username_password:
user_data.append(f"{k};{username_password[k]}")
out_file.write("
".join(user_data))
return new_username +","+ new_password
else:
print("Passwords do no match")
def add_task ():
task_username = input("Name of person assigned to task: ")
while task_username not in username_password.keys():
print("User does not exist. Please enter a valid username")
task_username = input("Enter a user who exists please.")
task_title = input("Title of Task: ")
task_description = input("Description of Task: ")
while True:
try:
task_due_date = input("Due date of task (YYYY-MM-DD): ")
due_date_time = datetime.strptime(task_due_date, DATETIME_STRING_FORMAT)
break
except ValueError:
print("Invalid datetime format. Please use the format specified")
# Then get the current date.
curr_date = date.today()
''' Add the data to the file task.txt and
Include 'No' to indicate if the task is complete.'''
new_task ={
"usern

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions