From 46ddf063cf7247e284bf2f7cc46549f3f902b8b0 Mon Sep 17 00:00:00 2001 From: LM <2609891867@qq.com> Date: Fri, 10 Jun 2022 21:18:16 +0800 Subject: [PATCH] =?UTF-8?q?[REFACTOR]=20=E5=B0=86Artical.py=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E7=9A=84=E5=89=8D=E7=AB=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=88=86=E7=A6=BB=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Article.py | 40 +++++++-------------------------- app/templates/userpage_get.html | 40 ++++++++++++++++++++++++++++++++- app/user_service.py | 11 +++++++-- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/app/Article.py b/app/Article.py index 774d25a..7d3aad5 100644 --- a/app/Article.py +++ b/app/Article.py @@ -61,22 +61,14 @@ def get_today_article(user_word_list, articleID): if within_range(text_level, user_level, (8.0 - user_level) * factor): d = reading break - - s = '' % ( - user_level, text_level) - s += '

Article added on: %s

' % (d['date']) - s += '
' + + article_date = d['date'] article_title = get_article_title(d['text']) article_body = get_article_body(d['text']) - s += '

%s

' % (article_title) - s += '

%s

' % (article_body) - s += '

%s

' % (d['source']) - s += '

%s

' % (get_question_part(d['question'])) - s = s.replace('\n', '
') - s += '%s' % (get_answer_part(d['question'])) - s += '
' - session['articleID'] = d['article_id'] - return s + question_part = get_question_part(d['question']) + answer_part = get_answer_part(d['question']) + return user_level,text_level,article_date,article_title,article_body,question_part,answer_part + def load_freq_history(path): @@ -103,7 +95,7 @@ def get_question_part(s): flag = 0 elif flag == 1: result.append(line) - return '\n'.join(result) + return result def get_answer_part(s): @@ -117,20 +109,4 @@ def get_answer_part(s): elif flag == 1: result.append(line) # https://css-tricks.com/snippets/javascript/showhide-element/ - js = ''' - - ''' - html_code = js - html_code += '\n' - html_code += '\n' - html_code += '\n' % ('\n'.join(result)) - return html_code \ No newline at end of file + return result \ No newline at end of file diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index d7cd982..da8a351 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -31,7 +31,45 @@

下一篇 Next Article

阅读文章并回答问题

-
{{ today_article|safe }}
+ +
+ +

Article added on: {{ article_date }}

+
+

{{ article_title }}

+

{{ article_body }}

+

+ {% for x in question_part %} + {{ x }} +
+ {% endfor %} +

+ +
+
+
+
+
生词高亮 diff --git a/app/user_service.py b/app/user_service.py index 139c140..bec8b17 100644 --- a/app/user_service.py +++ b/app/user_service.py @@ -117,11 +117,19 @@ def userpage(username): words = '' for x in lst3: words += x[0] + ' ' + user_level,text_level,article_date,article_title,article_body,question_part,answer_part = get_today_article(user_freq_record, session['articleID']) return render_template('userpage_get.html', username=username, session=session, flashed_messages=get_flashed_messages_if_any(), - today_article=get_today_article(user_freq_record, session['articleID']), + d=d, + user_level=user_level, + text_level=text_level, + article_date=article_date, + article_title=article_title, + article_body=article_body, + question_part=question_part, + answer_part=answer_part, d_len=len(d), lst3=lst3, yml=Yaml.yml, @@ -130,7 +138,6 @@ def userpage(username): - @userService.route("//mark", methods=['GET', 'POST']) def user_mark_word(username): '''