From 451feb7bbad40060cd6dc724190af1e03a5e9144 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 2 Aug 2021 16:52:02 +0800 Subject: [PATCH 1/9] app/main.py: flash a message after deleting a word from the new word list. --- app/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/main.py b/app/main.py index 3818ea6..024bac9 100644 --- a/app/main.py +++ b/app/main.py @@ -192,6 +192,15 @@ def get_answer_part(s): return html_code +def get_flashed_messages_if_any(): + messages = get_flashed_messages() + if messages == []: + return '' + s = '' + @app.route("//reset", methods=['GET', 'POST']) def user_reset(username): @@ -317,6 +326,7 @@ def familiar(username,word): def deleteword(username,word): user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username) pickle_idea2.deleteRecord(user_freq_record,word) + flash(f'Congratulations! {word} is no longer in your word list.') return redirect(url_for('userpage', username=username)) @app.route("/", methods=['GET', 'POST']) @@ -359,6 +369,7 @@ def userpage(username): page += 'EnglishPal Study Room for %s' % (username) page += '
' page += '

English Pal for %s 登出

' % (username) + page += get_flashed_messages_if_any() page += '

阅读文章并回答问题

\n' page += '

下一篇 Next Article

' % (username) page += '
%s
' % (get_today_article(user_freq_record, session['articleID'])) From f5086732f39e5e3539b68f1d70c427ef008528f9 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 2 Aug 2021 17:07:01 +0800 Subject: [PATCH 2/9] app/main.py: flash a message after deleting a word from the new word list (fix error). --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 024bac9..bc0be1b 100644 --- a/app/main.py +++ b/app/main.py @@ -369,7 +369,7 @@ def userpage(username): page += 'EnglishPal Study Room for %s' % (username) page += '
' page += '

English Pal for %s 登出

' % (username) - page += get_flashed_messages_if_any() + #page += get_flashed_messages_if_any() page += '

阅读文章并回答问题

\n' page += '

下一篇 Next Article

' % (username) page += '
%s
' % (get_today_article(user_freq_record, session['articleID'])) From 8abbf458a2788f8220ce3201481823f6a90e5641 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 2 Aug 2021 17:10:05 +0800 Subject: [PATCH 3/9] app/main.py: flash a message after deleting a word from the new word list (fix error - import get_flashed_messages). --- app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index bc0be1b..ac49b5d 100644 --- a/app/main.py +++ b/app/main.py @@ -13,7 +13,7 @@ import pickle_idea, pickle_idea2 import os import random, glob from datetime import datetime -from flask import Flask, request, redirect, render_template, url_for, session, abort, flash +from flask import Flask, request, redirect, render_template, url_for, session, abort, flash, get_flashed_messages from difficulty import get_difficulty_level, text_difficulty_level, user_difficulty_level app = Flask(__name__) @@ -369,7 +369,7 @@ def userpage(username): page += 'EnglishPal Study Room for %s' % (username) page += '
' page += '

English Pal for %s 登出

' % (username) - #page += get_flashed_messages_if_any() + page += get_flashed_messages_if_any() page += '

阅读文章并回答问题

\n' page += '

下一篇 Next Article

' % (username) page += '
%s
' % (get_today_article(user_freq_record, session['articleID'])) From 4773a6d131c6fc74a871cb330d870ceea8e1323f Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 2 Aug 2021 17:26:35 +0800 Subject: [PATCH 4/9] app/main.py: flash a message after deleting a word from the new word list (put f in the right place). --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index ac49b5d..6776f49 100644 --- a/app/main.py +++ b/app/main.py @@ -198,7 +198,7 @@ def get_flashed_messages_if_any(): return '' s = '
    ' for message in messages: - s += 'f
  • {message}
  • ' + s += f'
  • {message}
  • ' return s + '
' From 08bb7e0c40958d8e997177cffa24fdd1840d4582 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 2 Aug 2021 19:11:53 +0800 Subject: [PATCH 5/9] app/main.py: flash a message after deleting a word (use bootstrap alerts). --- app/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index 6776f49..5af6819 100644 --- a/app/main.py +++ b/app/main.py @@ -194,12 +194,12 @@ def get_answer_part(s): def get_flashed_messages_if_any(): messages = get_flashed_messages() - if messages == []: - return '' - s = '
    ' + s = '' for message in messages: - s += f'
  • {message}
  • ' - return s + '
' + s += '' + return s @app.route("//reset", methods=['GET', 'POST']) From 3d5130d68dee15f7c4a011a3803c63b35ce9eef4 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 2 Aug 2021 19:17:54 +0800 Subject: [PATCH 6/9] app/main.py: flash a message after deleting a word (use bootstrap alerts -- add additional content, e.g., a bolder congratulations). --- app/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 5af6819..44e2801 100644 --- a/app/main.py +++ b/app/main.py @@ -197,6 +197,7 @@ def get_flashed_messages_if_any(): s = '' for message in messages: s += '' return s @@ -326,7 +327,7 @@ def familiar(username,word): def deleteword(username,word): user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username) pickle_idea2.deleteRecord(user_freq_record,word) - flash(f'Congratulations! {word} is no longer in your word list.') + flash(f'{word} is no longer in your word list.') return redirect(url_for('userpage', username=username)) @app.route("/", methods=['GET', 'POST']) From c3dcc62879eee842dba0c9c53478c93cbdf59bab Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 2 Aug 2021 19:21:41 +0800 Subject: [PATCH 7/9] app/main.py: flash a message after deleting a word (use bootstrap alerts -- make the alert dismissable). --- app/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 44e2801..fea64c6 100644 --- a/app/main.py +++ b/app/main.py @@ -196,9 +196,12 @@ def get_flashed_messages_if_any(): messages = get_flashed_messages() s = '' for message in messages: - s += '