forked from mrlan/EnglishPal
Compare commits
5 Commits
Bug391-Liu
...
master
Author | SHA1 | Date |
---|---|---|
lin | b53e7031e5 | |
缪宸硕 | e48008550a | |
李凯 | fde3be4c23 | |
李凯 | 5d5f4cf8f2 | |
miaochenshuo | 260f62967b |
|
@ -62,13 +62,21 @@ def get_today_article(user_word_list, articleID):
|
||||||
d = reading
|
d = reading
|
||||||
break
|
break
|
||||||
|
|
||||||
article_date = d['date']
|
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>' % (
|
||||||
|
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'])
|
||||||
question_part = get_question_part(d['question'])
|
s += '<p class="display-3">%s</p>' % (article_title)
|
||||||
answer_part = get_answer_part(d['question'])
|
s += '<p class="lead"><font id="article" size=2>%s</font></p>' % (article_body)
|
||||||
return user_level,text_level,article_date,article_title,article_body,question_part,answer_part
|
s += '<p><small class="text-muted">%s</small></p>' % (d['source'])
|
||||||
|
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):
|
||||||
|
@ -95,7 +103,7 @@ def get_question_part(s):
|
||||||
flag = 0
|
flag = 0
|
||||||
elif flag == 1:
|
elif flag == 1:
|
||||||
result.append(line)
|
result.append(line)
|
||||||
return result
|
return '\n'.join(result)
|
||||||
|
|
||||||
|
|
||||||
def get_answer_part(s):
|
def get_answer_part(s):
|
||||||
|
@ -109,4 +117,20 @@ 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/
|
||||||
return result
|
js = '''
|
||||||
|
<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,6 +5,10 @@ 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')
|
||||||
|
@ -47,6 +51,8 @@ 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,9 +29,10 @@ 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> ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +41,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(list2[i], "g"), "<mark>" + list2[i] + "</mark>");
|
txt = txt.replace(new RegExp("\\s"+list2[i]+"\\s", "g"), " <mark>" + list2[i] + "</mark> ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,48 +30,8 @@
|
||||||
|
|
||||||
<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>
|
<div id="text-content">{{ today_article|safe }}</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,19 +117,11 @@ 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(),
|
||||||
d=d,
|
today_article=get_today_article(user_freq_record, session['articleID']),
|
||||||
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,
|
||||||
|
@ -138,6 +130,7 @@ 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