From 03145b57d98c29ae04948281e8e4e67512e75829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E9=97=AE=E4=B8=89=E4=B8=8D=E7=9F=A5?= <178428409@qq.com> Date: Fri, 21 Apr 2023 02:36:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BE=B9=E7=95=8C=E5=80=BC?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=88=E5=BD=93=E5=88=9A=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E5=B0=B1=E6=B2=A1=E6=9C=89=E6=89=BE=E5=88=B0=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E6=88=96=E8=80=85=E5=B0=B1=E6=A0=B9=E6=9C=AC=E8=A2=AB=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=96=87=E7=AB=A0=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C?= =?UTF-8?q?=E4=BC=9A=E5=87=BA=E7=8E=B0=E4=B8=8A=E4=B8=80=E7=AF=87=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Article.py | 5 +++-- app/templates/userpage_get.html | 8 +++++--- app/user_service.py | 18 +++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/Article.py b/app/Article.py index 9fc9c07..aac2c81 100644 --- a/app/Article.py +++ b/app/Article.py @@ -74,11 +74,12 @@ def get_today_article(user_word_list, had_read_articles): break if result_of_generate_article == "found": # 用于成功找到文章后及时退出外层循环 break - if result_of_generate_article != "found": # 阅读完所有文章,或者循环3次没有找到适合的文章,则对 index+=1 进行回滚 - had_read_articles["index"] -= 1 + if result_of_generate_article != "found": # 阅读完所有文章,或者循环3次没有找到适合的文章,则放入空(“null”) + had_read_articles["article_ids"].append('null') else: # 生成已经阅读过的文章 d = random.choice(result) text_level = text_difficulty_level(d['text'], d3) + result_of_generate_article = "found" today_article = None if d: diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index e2cb9d4..68948df 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -44,14 +44,16 @@ {# #} {# {% endfor %}#} - 下一篇 Next Article - {% if session.get('had_read_articles') != None and session.get('had_read_articles')["index"] !=0 %} + {% if result_of_generate_article != "had read all articles" %} + 下一篇 Next Article + {% endif %} + {% if session.get('had_read_articles') and session.get('had_read_articles')['index']>0 %} 上一篇 Previous Article {% endif %}

阅读文章并回答问题

- {% if today_article %} + {% if result_of_generate_article == 'found' %}

Article added on: {{ today_article["date"] }}



diff --git a/app/user_service.py b/app/user_service.py index a306724..4f81c6e 100644 --- a/app/user_service.py +++ b/app/user_service.py @@ -31,7 +31,10 @@ def user_reset(username): ''' if request.method == 'GET': had_read_articles = session.get("had_read_articles") - had_read_articles["index"] += 1 + if had_read_articles['article_ids'][-1] == "null": # 如果当前还是“null”,则将“null”pop出来,无需index+=1 + had_read_articles['article_ids'].pop() + else: # 当前不为“null”,直接 index+=1 + had_read_articles["index"] += 1 session["had_read_articles"] = had_read_articles return redirect(url_for('user_bp.userpage', username=username)) else: @@ -45,10 +48,11 @@ def user_back(username): :return: 返回页面内容 ''' if request.method == 'GET': - if session.get("found_article"): - had_read_articles = session.get("had_read_articles") - had_read_articles["index"] -= 1 - session["had_read_articles"] = had_read_articles + had_read_articles = session.get("had_read_articles") + had_read_articles["index"] -= 1 # 上一篇,index-=1 + if had_read_articles['article_ids'][-1] == "null": # 如果当前还是“null”,则将“null”pop出来 + had_read_articles['article_ids'].pop() + session["had_read_articles"] = had_read_articles return redirect(url_for('user_bp.userpage', username=username)) @@ -137,10 +141,6 @@ def userpage(username): words += x[0] + ' ' had_read_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('had_read_articles')) session['had_read_articles'] = had_read_articles - if today_article is None: - session["found_article"] = False - else: - session["found_article"] = True # 通过 today_article,加载前端的显示页面 return render_template('userpage_get.html', username=username,