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,