From 11aec35ad27b27c01fe5ef30d6959f6c1726bfe8 Mon Sep 17 00:00:00 2001 From: IssaIan Date: Mon, 10 Dec 2018 15:32:26 +0300 Subject: [PATCH] [starts #162539042]Add moderator user edit comment --- commandblog.py | 58 ++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/commandblog.py b/commandblog.py index 6daa24f..1450eca 100644 --- a/commandblog.py +++ b/commandblog.py @@ -28,12 +28,12 @@ } ] + def login(): username = input("please input username: ") for user in users: if user['name'] == username: - # return user['password'] password = input("please input password: ") if user['password'] != password: return 'Wrong password' @@ -41,15 +41,15 @@ def login(): if user['role'] == "normal": userinput = input("1. create comment \n 2.Edit comment \n 3. logout ") - + if userinput == str("1"): comment = input("Enter your comment:") - - data = {'comment_id': len(comments) +1, - 'comment': comment, - 'timestamp': datetime.datetime.now() , - 'created_by': username - } + + data = {'comment_id': len(comments) + 1, + 'comment': comment, + 'timestamp': datetime.datetime.now(), + 'created_by': username + } comments.append(data) return comments @@ -57,9 +57,10 @@ def login(): comment_id = int(input('Enter comment id:')) if not comment_id: return "Enter comment id" - comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False) + comment = next( + (comment for comment in comments if comment["comment_id"] == comment_id), False) if comment == False: - return "No comment found" + return "No comment found" edit = input("Enter your comment here:") comment["comment"] = edit return comments @@ -67,18 +68,18 @@ def login(): else: login() - - if user['role'] == "moderator": - userinput = input("1. create comment \n 2. edit comment \n 3. delete comment \n 4. logout \n ") - + elif user['role'] == "moderator": + userinput = input( + "1. create comment \n 2. edit comment \n 3. delete comment \n 4. logout \n ") + if userinput == str("1"): comment = input("Enter your comment:") - - data = {'comment_id': len(comments) +1, - 'comment': comment, - 'timestamp': datetime.datetime.now() , - 'created_by': username - } + + data = {'comment_id': len(comments) + 1, + 'comment': comment, + 'timestamp': datetime.datetime.now(), + 'created_by': username + } comments.append(data) return comments @@ -86,9 +87,10 @@ def login(): comment_id = int(input('Enter comment id:')) if not comment_id: return "Enter comment id: " - comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False) + comment = next( + (comment for comment in comments if comment["comment_id"] == comment_id), False) if comment == False: - return "No comment found" + return "No comment found" edit = input("Enter your comment here:") comment["comment"] = edit return comments @@ -96,19 +98,15 @@ def login(): comment_id = int(input('Enter comment id')) if not comment_id: return 'Enter comment id' - comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False) + comment = next( + (comment for comment in comments if comment["comment_id"] == comment_id), False) if comment == False: - return "No comment found" + return "No comment found" comments.remove(comment) return comments - else: login() - - - - -print(login()) \ No newline at end of file +print(login())