forked from mrlan/EnglishPal
Compare commits
2 Commits
master
...
Bug391-Liu
Author | SHA1 | Date |
---|---|---|
LM | 46ddf063cf | |
LM | dafe1717eb |
|
@ -62,21 +62,13 @@ def get_today_article(user_word_list, articleID):
|
||||||
d = reading
|
d = reading
|
||||||
break
|
break
|
||||||
|
|
||||||
s = '<div class="alert alert-success" role="alert">According to your word list, your level is <span class="badge bg-success">%4.2f</span> and we have chosen an article with a difficulty level of <span class="badge bg-success">%4.2f</span> for you.</div>' % (
|
article_date = d['date']
|
||||||
user_level, text_level)
|
|
||||||
s += '<p class="text-muted">Article added on: %s</p>' % (d['date'])
|
|
||||||
s += '<div class="p-3 mb-2 bg-light text-dark">'
|
|
||||||
article_title = get_article_title(d['text'])
|
article_title = get_article_title(d['text'])
|
||||||
article_body = get_article_body(d['text'])
|
article_body = get_article_body(d['text'])
|
||||||
s += '<p class="display-3">%s</p>' % (article_title)
|
question_part = get_question_part(d['question'])
|
||||||
s += '<p class="lead"><font id="article" size=2>%s</font></p>' % (article_body)
|
answer_part = get_answer_part(d['question'])
|
||||||
s += '<p><small class="text-muted">%s</small></p>' % (d['source'])
|
return user_level,text_level,article_date,article_title,article_body,question_part,answer_part
|
||||||
s += '<p><b>%s</b></p>' % (get_question_part(d['question']))
|
|
||||||
s = s.replace('\n', '<br/>')
|
|
||||||
s += '%s' % (get_answer_part(d['question']))
|
|
||||||
s += '</div>'
|
|
||||||
session['articleID'] = d['article_id']
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def load_freq_history(path):
|
def load_freq_history(path):
|
||||||
|
@ -103,7 +95,7 @@ def get_question_part(s):
|
||||||
flag = 0
|
flag = 0
|
||||||
elif flag == 1:
|
elif flag == 1:
|
||||||
result.append(line)
|
result.append(line)
|
||||||
return '\n'.join(result)
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_answer_part(s):
|
def get_answer_part(s):
|
||||||
|
@ -117,20 +109,4 @@ def get_answer_part(s):
|
||||||
elif flag == 1:
|
elif flag == 1:
|
||||||
result.append(line)
|
result.append(line)
|
||||||
# https://css-tricks.com/snippets/javascript/showhide-element/
|
# https://css-tricks.com/snippets/javascript/showhide-element/
|
||||||
js = '''
|
return result
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
function toggle_visibility(id) {
|
|
||||||
var e = document.getElementById(id);
|
|
||||||
if(e.style.display == 'block')
|
|
||||||
e.style.display = 'none';
|
|
||||||
else
|
|
||||||
e.style.display = 'block';
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
'''
|
|
||||||
html_code = js
|
|
||||||
html_code += '\n'
|
|
||||||
html_code += '<button onclick="toggle_visibility(\'answer\');">ANSWER</button>\n'
|
|
||||||
html_code += '<div id="answer" style="display:none;">%s</div>\n' % ('\n'.join(result))
|
|
||||||
return html_code
|
|
|
@ -5,10 +5,6 @@ from UseSqlite import InsertQuery, RecordQuery
|
||||||
path_prefix = '/var/www/wordfreq/wordfreq/'
|
path_prefix = '/var/www/wordfreq/wordfreq/'
|
||||||
path_prefix = './' # comment this line in deployment
|
path_prefix = './' # comment this line in deployment
|
||||||
|
|
||||||
def verify_pass(newpass,oldpass):
|
|
||||||
if(newpass==oldpass):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def verify_user(username, password):
|
def verify_user(username, password):
|
||||||
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
|
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
|
||||||
|
@ -51,8 +47,6 @@ def change_password(username, old_password, new_password):
|
||||||
if not verify_user(username, old_password): # 旧密码错误
|
if not verify_user(username, old_password): # 旧密码错误
|
||||||
return False
|
return False
|
||||||
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
|
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
|
||||||
if verify_pass(new_password,old_password): #新旧密码一致
|
|
||||||
return False
|
|
||||||
password = md5(username + new_password)
|
password = md5(username + new_password)
|
||||||
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')
|
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')
|
||||||
rq.instructions_with_parameters("UPDATE user SET password=:password WHERE name=:username", dict(
|
rq.instructions_with_parameters("UPDATE user SET password=:password WHERE name=:username", dict(
|
||||||
|
|
|
@ -29,10 +29,9 @@ function highLight() {
|
||||||
if (sel_word1 != null) {
|
if (sel_word1 != null) {
|
||||||
var list = sel_word1.value.split(" ");
|
var list = sel_word1.value.split(" ");
|
||||||
for (var i = 0; i < list.length; ++i) {
|
for (var i = 0; i < list.length; ++i) {
|
||||||
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");//消除字符串两边空字符
|
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");
|
||||||
if (list[i] != "" && "<mark>".indexOf(list[i]) == -1 && "</mark>".indexOf(list[i]) == -1) {
|
if (list[i] != "" && "<mark>".indexOf(list[i]) == -1 && "</mark>".indexOf(list[i]) == -1) {
|
||||||
|
txt = txt.replace(new RegExp(list[i], "g"), "<mark>" + list[i] + "</mark>");
|
||||||
txt = txt.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " <mark>" + list[i] + "</mark> ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +40,7 @@ function highLight() {
|
||||||
for (var i = 0; i < list2.length; ++i) {
|
for (var i = 0; i < list2.length; ++i) {
|
||||||
list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, "");
|
list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, "");
|
||||||
if (list2[i] != "" && "<mark>".indexOf(list2[i]) == -1 && "</mark>".indexOf(list2[i]) == -1) {
|
if (list2[i] != "" && "<mark>".indexOf(list2[i]) == -1 && "</mark>".indexOf(list2[i]) == -1) {
|
||||||
txt = txt.replace(new RegExp("\\s"+list2[i]+"\\s", "g"), " <mark>" + list2[i] + "</mark> ");
|
txt = txt.replace(new RegExp(list2[i], "g"), "<mark>" + list2[i] + "</mark>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,48 @@
|
||||||
|
|
||||||
<p><a class="btn btn-success" href="/{{ username }}/reset" role="button"> 下一篇 Next Article </a></p>
|
<p><a class="btn btn-success" href="/{{ username }}/reset" role="button"> 下一篇 Next Article </a></p>
|
||||||
<p><b>阅读文章并回答问题</b></p>
|
<p><b>阅读文章并回答问题</b></p>
|
||||||
<div id="text-content">{{ today_article|safe }}</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="text-content">
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
According to your word list, your level is
|
||||||
|
<span class="badge bg-success">{{ user_level }}</span>
|
||||||
|
and we have chosen an article with a difficulty level of
|
||||||
|
<span class="badge bg-success">{{ text_level }}</span>
|
||||||
|
for you.
|
||||||
|
</div>
|
||||||
|
<p class="text-muted">Article added on: {{ article_date }}</p>
|
||||||
|
<div class="p-3 mb-2 bg-light text-dark">
|
||||||
|
<p class="display-3">{{ article_title }}</p>
|
||||||
|
<p class="lead"><font id="article" size=2>{{ article_body }}</font></p>
|
||||||
|
<p><b>
|
||||||
|
{% for x in question_part %}
|
||||||
|
{{ x }}
|
||||||
|
</br>
|
||||||
|
{% endfor %}
|
||||||
|
</b></p>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function toggle_visibility(id) {
|
||||||
|
var e = document.getElementById(id);
|
||||||
|
if(e.style.display == 'block')
|
||||||
|
e.style.display = 'none';
|
||||||
|
else
|
||||||
|
e.style.display = 'block';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</br>
|
||||||
|
<button onclick="toggle_visibility('answer')">ANSWER</button></br>
|
||||||
|
<div id="answer" style="display:none;">
|
||||||
|
{% for x in answer_part %}
|
||||||
|
{{ x }}
|
||||||
|
</br>
|
||||||
|
{% endfor %}
|
||||||
|
</div></br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
<input type="checkbox" onclick="ChangeHighlight()" checked/>生词高亮
|
<input type="checkbox" onclick="ChangeHighlight()" checked/>生词高亮
|
||||||
<input type="checkbox" onclick="onReadClick()" checked/>大声朗读
|
<input type="checkbox" onclick="onReadClick()" checked/>大声朗读
|
||||||
<input type="checkbox" onclick="onChooseClick()" checked/>划词入库
|
<input type="checkbox" onclick="onChooseClick()" checked/>划词入库
|
||||||
|
|
|
@ -117,11 +117,19 @@ def userpage(username):
|
||||||
words = ''
|
words = ''
|
||||||
for x in lst3:
|
for x in lst3:
|
||||||
words += x[0] + ' '
|
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',
|
return render_template('userpage_get.html',
|
||||||
username=username,
|
username=username,
|
||||||
session=session,
|
session=session,
|
||||||
flashed_messages=get_flashed_messages_if_any(),
|
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),
|
d_len=len(d),
|
||||||
lst3=lst3,
|
lst3=lst3,
|
||||||
yml=Yaml.yml,
|
yml=Yaml.yml,
|
||||||
|
@ -130,7 +138,6 @@ def userpage(username):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@userService.route("/<username>/mark", methods=['GET', 'POST'])
|
@userService.route("/<username>/mark", methods=['GET', 'POST'])
|
||||||
def user_mark_word(username):
|
def user_mark_word(username):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue