From d9f6df7fbe585395a19b9a08c411d841b6b89fd4 Mon Sep 17 00:00:00 2001 From: huangdan <2741654266@qq.com> Date: Thu, 11 May 2023 15:51:10 +0800 Subject: [PATCH] =?UTF-8?q?AJAX=E8=BD=BD=E5=85=A5=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/userpage_get.html | 89 ++++++++++++++++++--------------- app/user_service.py | 29 +++++++---- 2 files changed, 69 insertions(+), 49 deletions(-) diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index 90c6114..e134d94 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -49,16 +49,12 @@ {# #} {# {% endfor %}#} - {% if result_of_generate_article != "had read all articles" %} - {% endif %} - {% if session.get('visited_articles') and session.get('visited_articles')['index']>0 %} - - {% endif %} +

阅读文章并回答问题

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

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



@@ -78,15 +74,13 @@
- {% elif result_of_generate_article == "not found" %} - - {% elif result_of_generate_article == "had read all articles" %} - - {% endif %} +
+ +
生词高亮 @@ -151,28 +145,20 @@ {% endfor %} {% endif %} - diff --git a/app/user_service.py b/app/user_service.py index 3d7670d..2e5feed 100644 --- a/app/user_service.py +++ b/app/user_service.py @@ -32,7 +32,12 @@ def get_next_article(username): else: # 当前不为“null”,直接 index+=1 visited_articles["index"] += 1 session["visited_articles"] = visited_articles - visited_articles, data, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles')) + visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles')) + data = { + 'visited_articles': visited_articles, + 'today_article': today_article, + 'result_of_generate_article': result_of_generate_article + } else: return 'Under construction' return json.dumps(data) @@ -42,11 +47,19 @@ def get_pre_article(username): user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username) if request.method == 'GET': visited_articles = session.get("visited_articles") - visited_articles["index"] -= 1 # 上一篇,index-=1 - if visited_articles['article_ids'][-1] == "null": # 如果当前还是“null”,则将“null”pop出来 - visited_articles['article_ids'].pop() - session["visited_articles"] = visited_articles - visited_articles, data, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles')) + if(visited_articles["index"]==0): + data='' + else: + visited_articles["index"] -= 1 # 上一篇,index-=1 + if visited_articles['article_ids'][-1] == "null": # 如果当前还是“null”,则将“null”pop出来 + visited_articles['article_ids'].pop() + session["visited_articles"] = visited_articles + visited_articles, today_article, result_of_generate_article = get_today_article(user_freq_record, session.get('visited_articles')) + data = { + 'visited_articles': visited_articles, + 'today_article': today_article, + 'result_of_generate_article':result_of_generate_article + } return json.dumps(data) @userService.route("///unfamiliar", methods=['GET', 'POST']) @@ -146,10 +159,6 @@ def userpage(username): yml=Yaml.yml, words=words) - - - - @userService.route("//mark", methods=['GET', 'POST']) def user_mark_word(username): '''