English Pal for {{ username }}
退出
@@ -29,6 +38,11 @@
{{ flashed_messages|safe }}
下一篇 Next Article
+ {% if session.get('articleID') == session.get('old_articleID') %}
+ {% if session.get('old_articleID') != None %}
+ 出bug了
+ {% endif%}
+ {% endif %}
{% if session.get('articleID') != session.get('old_articleID') %}
{% if session.get('old_articleID') != None %}
上一篇 Previous Article
From 0209548896d0dbbcfae95b0836306f5c1e0ed2f6 Mon Sep 17 00:00:00 2001
From: yugaoxiang
Date: Sat, 31 Dec 2022 18:25:13 +0800
Subject: [PATCH 12/70] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/main.py | 74 ++++++++++++++++++++-
app/templates/admin_index.html | 112 ++++++++++++++++++++++++++++++++
app/templates/mainpage_get.html | 4 +-
app/templates/userpage_get.html | 1 +
4 files changed, 188 insertions(+), 3 deletions(-)
create mode 100644 app/templates/admin_index.html
diff --git a/app/main.py b/app/main.py
index e311bb0..bcbd3f8 100644
--- a/app/main.py
+++ b/app/main.py
@@ -5,7 +5,7 @@
# Copyright 2019 (C) Hui Lan
# Written permission must be obtained from the author for commercial uses.
###########################################################################
-
+from datetime import datetime
from flask import escape
from Login import *
from Article import *
@@ -102,6 +102,78 @@ def mainpage():
d_len=d_len, lst=lst, yml=Yaml.yml)
+def insert_article(content, source='manual_input', level=5, question=''):
+ sql = f"INSERT into article (text,source, date, level, question) VALUES " \
+ f"('{content}','{source}','{datetime.now().strftime('%Y-%m-%d')}', '{level}', '{question}');"
+ print(sql)
+ rq = RecordQuery('./static/wordfreqapp.db')
+ rq.instructions(sql)
+ rq.do()
+
+
+def get_articles():
+ sql = f"SELECT * from article order by -article_id;"
+ rq = RecordQuery('./static/wordfreqapp.db')
+ rq.instructions(sql)
+ rq.do()
+ result = rq.get_results()
+ return result
+
+
+def get_users():
+ sql = f"SELECT * from user;"
+ rq = RecordQuery('./static/wordfreqapp.db')
+ rq.instructions(sql)
+ rq.do()
+ result = rq.get_results()
+ return result
+
+
+def update_user_password(username, password='123456'):
+ password = md5(username + password)
+ sql = f"UPDATE user SET password='{password}' where name='{username}';"
+ rq = RecordQuery('./static/wordfreqapp.db')
+ rq.instructions(sql)
+ rq.do()
+
+
+@app.route("/admin", methods=['GET', 'POST'])
+def admin():
+ '''
+ '''
+ # 未登录,跳转到未登录界面
+ if not session.get('logged_in'):
+ return render_template('not_login.html')
+
+ # 获取session里的用户名
+ username = session.get('username')
+
+ context = {
+ # 'user': request.user,
+ 'text_list': get_articles(),
+ 'user_list': get_users(),
+ 'username': username
+ }
+ if request.method == 'GET':
+ return render_template('admin_index.html', **context)
+ else:
+ data = request.form
+ content = data.get('content')
+ source = data.get('source', '')
+ question = data.get('question', '')
+ username = data.get('username')
+ if content:
+ insert_article(
+ content=content,
+ source=source,
+ question=question
+ )
+ context['text_list'] = get_articles()
+ if username:
+ update_user_password(username)
+ return render_template('admin_index.html', **context)
+
+
if __name__ == '__main__':
'''
diff --git a/app/templates/admin_index.html b/app/templates/admin_index.html
new file mode 100644
index 0000000..be88556
--- /dev/null
+++ b/app/templates/admin_index.html
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {% if tips %}
+
+ {{ tips }}
+
+ {% endif %}
+
+
+
+
+
+
文章列表
+
+ {% for text in text_list %}
+
+
+
{{ text['source'] }}
+ Date:{{ text['date'] }} Level:{{ text['level'] }}
+
+
{{ text['text'] }}
+
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/templates/mainpage_get.html b/app/templates/mainpage_get.html
index cbb51a6..4cc4417 100644
--- a/app/templates/mainpage_get.html
+++ b/app/templates/mainpage_get.html
@@ -23,9 +23,9 @@
English Pal - Learn English smartly!
{% if session['logged_in'] %}
-
{{session['username']}}
+
{{session['username']}} 管理
{% else %}
-
登录 注册 使用说明
+
管理 登录 注册 使用说明
{{random_ads|safe}}
{% endif %}
共有文章 {{number_of_essays}} 篇
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index 24bff60..863d2e4 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -23,6 +23,7 @@
English Pal for {{ username }}
+ 管理
退出
重设密码
From 43bd0bd09d3c345e52262ad2a3bfb58e83a39858 Mon Sep 17 00:00:00 2001
From: yugaoxiang
Date: Sun, 1 Jan 2023 22:05:32 +0800
Subject: [PATCH 13/70] update requirement.txt
---
requirements.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/requirements.txt b/requirements.txt
index 2746a3b..8552794 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
-Flask==1.1.2
+Flask==2.1.0
selenium==3.141.0
PyYAML~=6.0
From 03353d49b151ea730c1396077c10dde48cc81a32 Mon Sep 17 00:00:00 2001
From: mrlan
Date: Sun, 29 Jan 2023 10:57:58 +0800
Subject: [PATCH 14/70] Bug525-Hui (#79)
Co-authored-by: Hui Lan
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/79
Co-authored-by: mrlan
Co-committed-by: mrlan
---
app/Login.py | 4 ++--
app/templates/expiry.html | 2 +-
app/user_service.py | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/Login.py b/app/Login.py
index 1ada0af..8e0030b 100644
--- a/app/Login.py
+++ b/app/Login.py
@@ -1,6 +1,6 @@
import hashlib
import string
-from datetime import datetime
+from datetime import datetime, timedelta
from UseSqlite import InsertQuery, RecordQuery
path_prefix = '/var/www/wordfreq/wordfreq/'
@@ -23,7 +23,7 @@ def verify_user(username, password):
def add_user(username, password):
start_date = datetime.now().strftime('%Y%m%d')
- expiry_date = '20221230'
+ expiry_date = (datetime.now() + timedelta(days=30)).strftime('%Y%m%d') # will expire after 30 days
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
password = md5(username + password)
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')
diff --git a/app/templates/expiry.html b/app/templates/expiry.html
index 797a109..9464325 100644
--- a/app/templates/expiry.html
+++ b/app/templates/expiry.html
@@ -5,7 +5,7 @@
账号过期
- 您的账号{{ username }}过期。
+ 您的账号过期(过期日 {{expiry_date}})。
为了提高服务质量,English Pal 收取会员费用, 每天1元。
请决定你要试用的时间长度,扫描下面支付宝二维码支付。 支付时请注明English Pal Membership Fee。 我们会于12小时内激活账号。
diff --git a/app/user_service.py b/app/user_service.py
index 79c7888..2d10404 100644
--- a/app/user_service.py
+++ b/app/user_service.py
@@ -107,7 +107,7 @@ def userpage(username):
# 用户过期
user_expiry_date = session.get('expiry_date')
if datetime.now().strftime('%Y%m%d') > user_expiry_date:
- return render_template('expiry.html')
+ return render_template('expiry.html', expiry_date=user_expiry_date)
# 获取session里的用户名
username = session.get('username')
From 972a1a5524dde8fcdea9ad3b63f7e397ebba504a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E7=A7=8B=E4=BC=9F?= <2658626578@qq.com>
Date: Sun, 29 Jan 2023 11:49:27 +0800
Subject: [PATCH 15/70] Bug490-ChenQiuwei (#63)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修复Bug-490,使注册时确认密码能够发挥作用,在确认密码与所设置密码不一致时,能够提示“确认密码与输入密码不一致”。
Co-authored-by: 2658626578 <2658626578@qq.com>
Co-authored-by: Hui Lan
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/63
Co-authored-by: 陈秋伟 <2658626578@qq.com>
Co-committed-by: 陈秋伟 <2658626578@qq.com>
---
app/account_service.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/app/account_service.py b/app/account_service.py
index dc854a3..9b1c46b 100644
--- a/app/account_service.py
+++ b/app/account_service.py
@@ -5,7 +5,6 @@ from Login import check_username_availability, verify_user, add_user, get_expiry
# 初始化蓝图
accountService = Blueprint("accountService", __name__)
-
### Sign-up, login, logout ###
@accountService.route("/signup", methods=['GET', 'POST'])
def signup():
@@ -20,6 +19,7 @@ def signup():
# POST方法需判断是否注册成功,再根据结果返回不同的内容
username = escape(request.form['username'])
password = escape(request.form['password'])
+ password2 = escape(request.form['password2'])
#! 添加如下代码为了过滤注册时的非法字符
warn = WarningMessage(username)
@@ -32,6 +32,8 @@ def signup():
return render_template('signup.html')
elif len(password.strip()) < 4: # 密码过短
return '密码过于简单。'
+ elif password != password2:
+ return '确认密码与输入密码不一致!'
else: # 添加账户信息
add_user(username, password)
verified = verify_user(username, password)
@@ -48,6 +50,7 @@ def signup():
return '用户名密码验证失败。'
+
@accountService.route("/login", methods=['GET', 'POST'])
def login():
'''
From 9cdc9c6f7fe06fcdb485c9ca038f953a67cf30e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=9B=A8=E5=B3=B0?= <1141730046@qq.com>
Date: Sun, 29 Jan 2023 12:01:19 +0800
Subject: [PATCH 16/70] Bug521-LiYuFeng-Refactor (#72)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
@mrlan
蓝老师:
本次改进内容如下:
1. 对生词居中问题进行修改,现在已经不会居中了。
2. 对于单词数量基数大而导致的排序速度慢的问题,我们进行了优化,提升了排序的速度。
3. 对用户交互进行了优化,当用户点击“熟悉”或“不熟悉”之后,会自动进行排序,并会跳转到那个单词的位置,用抖动的效果来提示用户。
Co-authored-by: isaac <1141730046@qq.com>
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/72
Co-authored-by: 李雨峰 <1141730046@qq.com>
Co-committed-by: 李雨峰 <1141730046@qq.com>
---
app/static/js/word_operation.js | 139 ++++++++++++++++++++++++++++++--
app/templates/userpage_get.html | 64 ++++++++++-----
2 files changed, 177 insertions(+), 26 deletions(-)
diff --git a/app/static/js/word_operation.js b/app/static/js/word_operation.js
index a55fb6e..a9af300 100644
--- a/app/static/js/word_operation.js
+++ b/app/static/js/word_operation.js
@@ -7,10 +7,20 @@ function familiar(theWord) {
url:"/" + username + "/" + word + "/familiar",
success:function(response){
let new_freq = freq - 1;
- if(new_freq <1) {
- $("#p_" + theWord).remove();
+ const allow_move = document.getElementById("move_dynamiclly").checked;
+ if (allow_move) {
+
+ if (new_freq <= 0) {
+ removeWord(theWord);
+ } else {
+ renderWord({ word: theWord, freq: new_freq });
+ }
} else {
- $("#freq_" + theWord).text(new_freq);
+ if(new_freq <1) {
+ $("#p_" + theWord).remove();
+ } else {
+ $("#freq_" + theWord).text(new_freq);
+ }
}
}
});
@@ -25,7 +35,12 @@ function unfamiliar(theWord) {
url:"/" + username + "/" + word + "/unfamiliar",
success:function(response){
let new_freq = parseInt(freq) + 1;
- $("#freq_" + theWord).text(new_freq);
+ const allow_move = document.getElementById("move_dynamiclly").checked;
+ if (allow_move) {
+ renderWord({ word: theWord, freq: new_freq });
+ } else {
+ $("#freq_" + theWord).text(new_freq);
+ }
}
});
}
@@ -37,7 +52,121 @@ function delete_word(theWord) {
type:"GET",
url:"/" + username + "/" + word + "/del",
success:function(response){
- $("#p_" + theWord).remove();
+ const allow_move = document.getElementById("move_dynamiclly").checked;
+ if (allow_move) {
+ removeWord(theWord);
+ } else {
+ $("#p_" + theWord).remove();
+ }
}
});
}
+
+/*
+ * interface Word {
+ * word: string,
+ * freq: number
+ * }
+* */
+
+/**
+ * 传入一个词频HTML元素,将其解析为Word类型的对象
+ */
+function parseWord(element) {
+ const word = element
+ .querySelector("a.btn.btn-light[role=button]") // 获取当前词频元素的词汇元素
+ .innerText // 获取词汇值;
+ const freq = Number.parseInt(element.querySelector(`#freq_${word}`).innerText); // 获取词汇的数量
+ return {
+ word,
+ freq
+ };
+}
+
+/**
+ * 使用模板将传入的单词转换为相应的HTML字符串
+*/
+function wordTemplate(word) {
+ // 这个模板应当与 templates/userpage_get.html 中的 ...
保持一致
+ return `
+ ${word.word}
+ ( ${word.freq} )
+ 熟悉
+ 不熟悉
+ 删除
+
`;
+}
+
+/**
+ * 删除某一词频元素
+ * 此处word为词频元素对应的单词
+ */
+function removeWord(word) {
+ // 根据词频信息删除元素
+ const element_to_remove = document.getElementById(`p_${word}`);
+ if (element_to_remove != null) {
+ element_to_remove.remove();
+ }
+}
+
+function renderWord(word) {
+ const container = document.querySelector(".word-container");
+ // 删除原有元素
+ removeWord(word.word);
+ // 插入新元素
+ let inserted = false;
+ const new_element = elementFromString(wordTemplate(word));
+ for (const current of container.children) {
+ const cur_word = parseWord(current);
+ // 找到第一个词频比它小的元素,插入到这个元素前面
+ if (compareWord(cur_word, word) == -1) {
+ container.insertBefore(new_element, current);
+ inserted = true;
+ break;
+ }
+ }
+ // 当word就是词频最小的词时,把他补回去
+ if (!inserted) {
+ container.appendChild(new_element);
+ }
+ // 让发生变化的元素抖动
+ new_element.classList.add("shaking");
+ // 移动到该元素
+ new_element.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
+ // 抖动完毕后删除抖动类
+ setTimeout(() => {
+ new_element.classList.remove("shaking");
+ }, 1600);
+}
+
+/**
+ * 从string中创建一个HTML元素并返回
+ */
+function elementFromString(string) {
+ const d = document.createElement('div');
+ d.innerHTML = string;
+ return d.children.item(0);
+}
+
+/**
+ * 对比两个单词:
+ * 当first小于second时返回-1
+ * 当first等于second时返回0
+ * 当first大于second时返回1
+ */
+function compareWord(first, second) {
+ if (first.freq < second.freq) {
+ return -1;
+ }
+ if (first.freq > second.freq) {
+ return 1;
+ }
+ if (first.word < second.word) {
+ return -1;
+ }
+ if (first.word > second.word) {
+ return 1;
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index 24bff60..dc0d497 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -19,19 +19,33 @@
{% endif %}
EnglishPal Study Room for {{ username }}
+
+
English Pal for {{ username }}
- 退出
- 重设密码
+ 退出
+ 重设密码
{{ flashed_messages|safe }}
-
下一篇 Next Article
+
下一篇 Next Article
{% if session.get('articleID') != session.get('old_articleID') %}
{% if session.get('old_articleID') != None %}
-
上一篇 Previous Article
+
上一篇 Previous Article
{% endif%}
{% endif %}
@@ -52,7 +66,7 @@
收集生词吧 (可以在正文中划词,也可以复制黏贴)
{% if session.get['thisWord'] %}
@@ -67,22 +81,30 @@
{% endif %}
{% if d_len > 0 %}
-
我的生词簿
- {% for x in lst3 %}
- {% set word = x[0] %}
- {% set freq = x[1] %}
- {% if session.get('thisWord') == x[0] and session.get('time') == 1 %}
-
- {% endif %}
-
- {{ word }}
- ( {{ freq }} )
- 熟悉
- 不熟悉
- 删除
-
- {% endfor %}
+
+ 我的生词簿
+
+
+
+
+ {% for x in lst3 %}
+ {% set word = x[0] %}
+ {% set freq = x[1] %}
+ {% if session.get('thisWord') == x[0] and session.get('time') == 1 %}
+ {% endif %}
+
+ {{ word }}
+ ( {{ freq }} )
+ 熟悉
+ 不熟悉
+ 删除
+
+ {% endfor %}
+
{% endif %}
From e10dbf9d67114e36e77bb773b631435844b3655c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=BF=97=E8=B1=AA?= <1594799762@qq.com>
Date: Sun, 29 Jan 2023 12:48:52 +0800
Subject: [PATCH 17/70] Bug507-WuWenZhuo (#70)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
### 修复了生词簿为空时,双击文章单词无法高亮的问题
通过增加一个判断,判断生词簿为空时,不把生词簿的内容进行处理,仅处理选中单词。
### 修复了生词簿为空时,取消高亮后,导致文章格式混乱的问题
原代码中,从数据库提取文章放到网页上时,使用的是.innerText的方法,导致原文章里包含的
标签丢失,导致文章格式混乱的问题。
Co-authored-by: unknown
Co-authored-by: Hui Lan
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/70
Co-authored-by: 王志豪 <1594799762@qq.com>
Co-committed-by: 王志豪 <1594799762@qq.com>
---
README.md | 3 +++
app/static/js/highlight.js | 22 ++++++++++++++--------
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index fb70948..c12fc0b 100644
--- a/README.md
+++ b/README.md
@@ -191,4 +191,7 @@ Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=215
Bug report:http://118.25.96.118/bugzilla/show_bug.cgi?id=489
+=======
+实验3,添加我的组名:WuWenZhuo
+
*Last modified on 2021-10-17*
\ No newline at end of file
diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js
index 7b3cab2..5ec9663 100644
--- a/app/static/js/highlight.js
+++ b/app/static/js/highlight.js
@@ -22,11 +22,17 @@ function getWord() {
function highLight() {
if (!isHighlight) return;
- let articleContent = document.getElementById("article").innerText;
+ let articleContent = document.getElementById("article").innerText; //将原来的.innerText改为.innerHtml,使用innerText会把原文章中所包含的
标签去除,导致处理后的文章内容失去了原来的格式
let pickedWords = document.getElementById("selected-words"); // words picked to the text area
let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list
- let allWords = pickedWords.value + " " + dictionaryWords.value;
- const list = allWords.split(" ");
+ let allWords = ""; //初始化allWords的值,避免进入判断后编译器认为allWords未初始化的问题
+ if(dictionaryWords != null){//增加一个判断,检查生词本里面是否为空,如果为空,allWords只添加选中的单词
+ allWords = pickedWords.value + " " + dictionaryWords.value;
+ }
+ else{
+ allWords = pickedWords.value + " ";
+ }
+ const list = allWords.split(" ");//将所有的生词放入一个list中,用于后续处理
for (let i = 0; i < list.length; ++i) {
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除单词两边的空字符
list[i] = list[i].replace('|', "");
@@ -40,15 +46,15 @@ function highLight() {
}
function cancelHighlighting() {
- let articleContent = document.getElementById("article").innerText;
+ let articleContent = document.getElementById("article").innerText;//将原来的.innerText改为.innerHtml,原因同上
let pickedWords = document.getElementById("selected-words");
const dictionaryWords = document.getElementById("selected-words2");
const list = pickedWords.value.split(" ");
if (pickedWords != null) {
for (let i = 0; i < list.length; ++i) {
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");
- if (list[i] !== "") {
- articleContent = articleContent.replace("" + list[i] + "", "list[i]");
+ if (list[i] !== "") { //原来判断的代码中,替换的内容为“list[i]”这个字符串,这明显是错误的,我们需要替换的是list[i]里的内容
+ articleContent = articleContent.replace(new RegExp(""+list[i]+"", "g"), list[i]);
}
}
}
@@ -57,8 +63,8 @@ function cancelHighlighting() {
for (let i = 0; i < list2.length; ++i) {
list2 = dictionaryWords.value.split(" ");
list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, "");
- if (list2[i] !== "") {
- articleContent = articleContent.replace("" + list[i] + "", "list[i]");
+ if (list2[i] !== "") { //原来代码中,替换的内容为“list[i]”这个字符串,这明显是错误的,我们需要替换的是list[i]里的内容
+ articleContent = articleContent.replace(new RegExp(""+list2[i]+"", "g"), list2[i]);
}
}
}
From 92a8b4a9944b9509e52cd09a7eb35aa4ccb052b4 Mon Sep 17 00:00:00 2001
From: mrlan
Date: Mon, 30 Jan 2023 15:44:01 +0800
Subject: [PATCH 18/70] Lanhui-update-README2 (#80)
Co-authored-by: Lan Hui <1348141770@qq.com>
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/80
Co-authored-by: mrlan
Co-committed-by: mrlan
---
.DS_Store | Bin 6148 -> 0 bytes
README.md | 65 ++++++++++++++++++++++++++----------------------------
2 files changed, 31 insertions(+), 34 deletions(-)
delete mode 100644 .DS_Store
diff --git a/.DS_Store b/.DS_Store
deleted file mode 100644
index 7b9e3399d7747d6de8838936b3d6673c4464d460..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 6148
zcmeHK%Wl&^6g|@f>NG;i0;Fy#Sz=p-RE1Wk8#km2kl54+7Jx!r8*0_@gxDdKqDWc8
zKky4|`4awx6`Xlgic`8_flxG8nmKo7?wRX3)_6PsM0XPJ0WAO?i^BRAt3Q|;SLK>*
z*d8?~)Ex3G%4Ecrn$DS1z$x&*E1>pn4FilYdYV=C?=eT(zqIK^*r;e)jO;G|9*wfJ
zC_9}WVxv~Sb$ip>^qSt=@LW#Aa!^i+?qK{{wO&Y>MOXeHdYLBEe(UZNnU{k!PsW;%
z#tB2-yh`&}PP=lF$A#vGX25HBjecu;HrspD+4c7yAIx|C+2JAmhx-TfdBeMR|H08|
z{~{aa^0N_L@SCLVj>RkZLdUM=Q#j5unSWr9iuMp;f)p8Iv{B%EMU!ugS=M9=JxHA4
z0tv==ubD}eBX(9eO*~_CPEN|YxPhgfaXC{1r#Qhe^F1fFF+{wQ=jRHe#V1PeQLjgN
zL!Gr`#x_b^qO9^cH}G}oeY5Fotrf8Q!)vbfD&69o0#1RyQ9ykkd=`a)#f3rr>0qU=
z0K_`Gwb9o<|3qJP5Ce+~gY2ORLnRujuvZLW?+(JyIUd;fg+W7y(3v@p%`EHvBoKj-xvs)*8l(j
diff --git a/README.md b/README.md
index c12fc0b..29e74dd 100644
--- a/README.md
+++ b/README.md
@@ -11,15 +11,14 @@ Hui Lan
EnglishPal allows the user to build his list of new English words
-picked from articles selected for him according his vocabulary level.
+picked from articles selected for him to read according his vocabulary level. EnglishPal will determine a user's vocabulary level based on his picked words. After that, it will recommend articles for him to read, in order to booster his English vocabulary furthermore.
-## Run it on a local machine
-
+## Run on your own laptop
`python3 main.py`
-Make sure you have the SQLite database file in `app/static` (see below).
+Make sure you have put the SQLite database file in the path `app/static` (see below).
## Run it as a Docker container
@@ -29,32 +28,32 @@ Assuming that docker has been installed and that you are a sudo user (i.e., sudo
`sudo ./build.sh`
-Open your favourite Internet browser and enter this URL address: `http://ip-address:90`.
+Open your favourite Internet browser and enter this URL address: `http://ip-address:90`. Note: you must update the variable `DEPLOYMENT_DIR` in `build.sh`.
### Explanation on the commands in build.sh
-My steps for deploying English on the server.
+My steps for deploying English on a Ubuntu server.
- ssh to ubuntu@118.*.*.118
-- cd to /home/lanhui/englishpal2/EnglishPal
+- cd to `/home/lanhui/englishpal2/EnglishPal`
- Stop all docker service: `sudo service docker restart`. If you know the docker container ID, then the above command is an overkill. Use the following command instead: `sudo docker stop ContainerID`. You could get all container IDs with the following command: `sudo docker ps`
-- Rebuild container. Run the following command to rebuild a docker image after the code gets updated: `sudo docker build -t englishpal .`
+- Rebuild container. Run the following command to rebuild a docker image each time after the source code gets updated: `sudo docker build -t englishpal .`
-- Run the application: `sudo docker run -d -p 90:80 -v /home/lanhui/englishpal2/EnglishPal/app/static/frequency:/app/static/frequency -t englishpal`. If you use `sudo docker run -d -p 90:80 -t englishpal`, data will be lost after terminating the program.
+- Run the application: `sudo docker run -d -p 90:80 -v /home/lanhui/englishpal2/EnglishPal/app/static/frequency:/app/static/frequency -t englishpal`. If you use `sudo docker run -d -p 90:80 -t englishpal`, data will be lost after terminating the program. If you want to automatically restart the docker image after each system reboot, add the option `--restart=always` after `docker run`.
-- Save space: `sudo docker system prune -a -f`
+- Save disk space: `sudo docker system prune -a -f`
+
+`build.sh` contains all the above commands. Run "sudo ./build.sh" to rebuild and start the web application.
-### Other useful docker commands
+#### Other useful docker commands
- `sudo docker ps -a`
-- `sudo docker logs image_name`, where image_name could be obtained from `sudo docker ps`.
-
-`build.sh` contains all the above commands. Run "sudo ./build.sh" to rebuild and run the web application.
+- `sudo docker logs image_name`, where `image_name` could be obtained from `sudo docker ps`.
@@ -68,6 +67,10 @@ All articles are stored in the `article` table in a SQLite file called
To add articles, open and edit `app/static/wordfreqapp.db` using DB Browser for SQLite (https://sqlitebrowser.org).
+### Extending an account's expiry date
+
+By default, an account's expiry is 30 days after first sign-up. To extend account's expiry date, open and edit `user` table in `app/static/wordfreqapp.db`. Simply update field `expiry_date`.
+
### Exporting the database
Export wordfreqapp.db to wordfreqapp.sql using the following commands:
@@ -92,33 +95,31 @@ sqlite3 wordfreqapp.db`. Delete wordfreqapp.db first if it exists.
### Uploading wordfreqapp.db to the server
-`pscp wordfreqapp.db lanhui@118.*.*.118:/home/lanhui/englishpal/app/static`
+`pscp wordfreqapp.db lanhui@118.*.*.118:/home/lanhui/englishpal2/EnglishPal/app/static`
## Feedback
-We welcome feedback on EnglishPal.
+We welcome feedback on EnglishPal. Feedback examples:
-### Respondent 1
+### Feedback 1
+
+- "Need a phone app. I use phone a lot. You cannot ask students to use computers."
-"Need a phone app. I use phone a lot. You cannot ask students to use computers."
-
-Can take a picture for text. Automatic translation.
-
-### Respondent 2
+### Feedback 2
-“成为会员”改成“注册”
+- “成为会员”改成“注册”
-“登出”改成“退出”
+- “登出”改成“退出”
-“收集生词吧”改成“生词收集栏”
+- “收集生词吧”改成“生词收集栏”
-“不要自动显示下一篇”
+- 不要自动显示下一篇
-需要有“上一篇”、“下一篇”
+- 需要有“上一篇”、“下一篇”按钮。
@@ -137,7 +138,7 @@ EnglishPal's bugs and improvement suggestions are recorded in [Bugzilla](http://
- Usability testing
-## Improvements made by contributors
+## Improvements made by contributors (incomplete list)
### 朱文绮
@@ -159,7 +160,6 @@ too many words that they already know, on the other hand, it can
reduce unnecessary memory occupied by the database, in addition, it
can also improve the simplicity of the page.
-More information at: http://118.25.96.118/kanboard/?controller=TaskViewController&action=readonly&task_id=736&token=81a561da57ff7a172da17a480f0d421ff3bc69efbd29437daef90b1b8959
### 占健豪
@@ -188,10 +188,7 @@ Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=215
漏洞:新用户在创建账号时,不需要输入确定密码也可以注册成功,并且新账户可以正常使用。
-Bug report:http://118.25.96.118/bugzilla/show_bug.cgi?id=489
+Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=489
-=======
-实验3,添加我的组名:WuWenZhuo
-
-*Last modified on 2021-10-17*
\ No newline at end of file
+*Last modified on 2023-01-30*
\ No newline at end of file
From a1955341c6c2495dd7c8f73727d341b780c38a6c Mon Sep 17 00:00:00 2001
From: Hui Lan
Date: Tue, 31 Jan 2023 16:39:11 +0800
Subject: [PATCH 19/70] =?UTF-8?q?Fix=20bug=20501=20-=20=E7=89=B9=E6=AE=8A?=
=?UTF-8?q?=E5=AD=97=E7=AC=A6&=E5=8A=A0=E5=85=A5=E7=94=9F=E8=AF=8D?=
=?UTF-8?q?=E5=BA=93=E5=90=8E=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE=E5=A4=B1?=
=?UTF-8?q?=E6=95=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/static/js/word_operation.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/app/static/js/word_operation.js b/app/static/js/word_operation.js
index a9af300..ea6a6e8 100644
--- a/app/static/js/word_operation.js
+++ b/app/static/js/word_operation.js
@@ -47,7 +47,7 @@ function unfamiliar(theWord) {
function delete_word(theWord) {
let username = $("#username").text();
- let word = $("#word_" + theWord).text();
+ let word = theWord.replace('&', '&');
$.ajax({
type:"GET",
url:"/" + username + "/" + word + "/del",
@@ -104,6 +104,7 @@ function wordTemplate(word) {
*/
function removeWord(word) {
// 根据词频信息删除元素
+ word = word.replace('&', '&');
const element_to_remove = document.getElementById(`p_${word}`);
if (element_to_remove != null) {
element_to_remove.remove();
@@ -169,4 +170,4 @@ function compareWord(first, second) {
return 1;
}
return 0;
-}
\ No newline at end of file
+}
From 93390374ad3e67568c3a2ce5376f683734516a0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=80=E9=97=AE=E4=B8=89=E4=B8=8D=E7=9F=A5?=
<178428409@qq.com>
Date: Tue, 21 Feb 2023 20:05:48 +0800
Subject: [PATCH 20/70] =?UTF-8?q?=E6=A0=87=E6=B3=A8=E4=B9=8B=E5=89=8D?=
=?UTF-8?q?=E9=98=9F=E4=BC=8D=E7=9A=84=E6=94=B9=E5=8A=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/templates/userpage_get.html | 42 +++++++++++++++++++--------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index 7d8f981..ee9a7f0 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -17,18 +17,21 @@
{% endfor %}
{% endif %}
-
+{# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
EnglishPal Study Room for {{ username }}
+{# original code: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
English Pal for {{ username }}
@@ -37,17 +40,19 @@
{{ flashed_messages|safe }}
-
下一篇 Next Article
+
下一篇 Next Article
+{# add code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
{% if session.get('articleID') == session.get('old_articleID') %}
{% if session.get('old_articleID') != None %}
出bug了
- {% endif%}
+ {% endif %}
{% endif %}
{% if session.get('articleID') != session.get('old_articleID') %}
{% if session.get('old_articleID') != None %}
上一篇 Previous Article
- {% endif%}
+ {% endif %}
{% endif %}
+{# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
阅读文章并回答问题
{{ today_article|safe }}
@@ -60,9 +65,9 @@
1×
-
+
-
+
收集生词吧 (可以在正文中划词,也可以复制黏贴)
{% else %}
登录 注册 使用说明
-
{{random_ads|safe}}
+
{{ random_ads }}。 试试吧!
{% endif %}
共有文章 {{number_of_essays}} 篇
粘贴1篇文章 (English only)
diff --git a/app/templates/reset.html b/app/templates/reset.html
index 902d046..d29855b 100644
--- a/app/templates/reset.html
+++ b/app/templates/reset.html
@@ -2,6 +2,38 @@
+
+
@@ -9,14 +41,11 @@
Reset Password
-
+
+
+
+
+
{% endblock %}
\ No newline at end of file
diff --git a/app/templates/signup.html b/app/templates/signup.html
index 1fd05f0..c70e4ba 100644
--- a/app/templates/signup.html
+++ b/app/templates/signup.html
@@ -6,6 +6,47 @@ You're logged in already!
Logout.
{% else %}
+
+
{{ get_flashed_messages()[0] | safe }}
@@ -15,12 +56,10 @@ You're logged in already!
Logout.
Sign Up
-
+
+
+
+
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index ea91c58..5ef86c7 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -18,17 +18,6 @@
{% endfor %}
{% endif %}
-{# // add !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
-
-{# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
English Pal for {{ username }}
退出
重设密码
- {{ flashed_messages|safe }}
+ {% for message in messages %}
+
Congratulations! {{ message }}
+ {% endfor %}
下一篇 Next Article
-{# add code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
- {% if session.get('articleID') == session.get('old_articleID') %}
- {% if session.get('old_articleID') != None %}
-
出bug了
- {% endif %}
+ {% if session.get('existing_articles')[0] != None and session.get('existing_articles')[0] !=0 %}
+
上一篇 Previous Article
{% endif %}
- {% if session.get('articleID') != session.get('old_articleID') %}
- {% if session.get('old_articleID') != None %}
-
上一篇 Previous Article
- {% endif %}
- {% endif %}
-{# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
阅读文章并回答问题
-
{{ today_article|safe }}
+
+ {% if today_article %}
+
According to your word list, your level is {{ today_article["user_level"] }} and we have chosen an article with a difficulty level of {{ today_article["text_level"] }} for you.
+
Article added on: {{ today_article["date"] }}
+
+
{{ today_article["article_title"] }}
+
{{ today_article["article_body"] }}
+
{{ today_article['source'] }}
+
{{ today_article['question'] }}
+
+
+
{{ today_article['answer'] }}
+
+ {% else %}
+
+
Notes:
No article is currently available for you. You can try again a few times or mark new words in the passage to improve your level.
+
+ {% endif %}
+
生词高亮
大声朗读
diff --git a/app/user_service.py b/app/user_service.py
index 2d10404..2c91391 100644
--- a/app/user_service.py
+++ b/app/user_service.py
@@ -29,9 +29,10 @@ def user_reset(username):
:param username: 用户名
:return: 返回页面内容
'''
- session['old_articleID'] = session.get('articleID')
if request.method == 'GET':
- session['articleID'] = None
+ existing_articles = session.get("existing_articles")
+ existing_articles[0] += 1
+ session["existing_articles"] = existing_articles
return redirect(url_for('user_bp.userpage', username=username))
else:
return 'Under construction'
@@ -44,7 +45,9 @@ def user_back(username):
:return: 返回页面内容
'''
if request.method == 'GET':
- session['articleID'] = session.get('old_articleID')
+ existing_articles = session.get("existing_articles")
+ existing_articles[0] -= 1
+ session["existing_articles"] = existing_articles
return redirect(url_for('user_bp.userpage', username=username))
@@ -130,11 +133,14 @@ def userpage(username):
words = ''
for x in lst3:
words += x[0] + ' '
+ existing_articles, today_article = get_today_article(user_freq_record, session.get('existing_articles'))
+ session['existing_articles'] = existing_articles
+ # 通过 today_article,加载前端的显示页面
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']),
+ flashed_messages=get_flashed_messages(),
+ today_article=today_article,
d_len=len(d),
lst3=lst3,
yml=Yaml.yml,
@@ -173,15 +179,3 @@ def get_time():
'''
return datetime.now().strftime('%Y%m%d%H%M') # upper to minutes
-def get_flashed_messages_if_any():
- '''
- 在用户界面显示黄色提示信息
- :return: 包含HTML标签的提示信息
- '''
- messages = get_flashed_messages()
- s = ''
- for message in messages:
- s += '
'
- s += f'Congratulations! {message}'
- s += '
'
- return s
From 376ef9bcbcd32298895e6875bbc307c84e962a2e Mon Sep 17 00:00:00 2001
From: Awoodwhale
Date: Mon, 20 Mar 2023 20:08:14 +0800
Subject: [PATCH 22/70] feat: add pong orm requirement
---
requirements.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/requirements.txt b/requirements.txt
index 8552794..1972e7d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
Flask==2.1.0
selenium==3.141.0
PyYAML~=6.0
+pony==0.7.16
From df82748518afdabf323696ad7dfce0ff6265e0ca Mon Sep 17 00:00:00 2001
From: Awoodwhale
Date: Mon, 20 Mar 2023 20:09:32 +0800
Subject: [PATCH 23/70] feat: create classes necessary for orm operations
---
app/model.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 app/model.py
diff --git a/app/model.py b/app/model.py
new file mode 100644
index 0000000..a913e65
--- /dev/null
+++ b/app/model.py
@@ -0,0 +1,30 @@
+from pony.orm import *
+
+db = Database()
+db.bind("sqlite", "./static/wordfreqapp.db", create_db=True) # bind sqlit file
+
+
+class User(db.Entity):
+ _table_ = "user" # table name
+ name = PrimaryKey(str)
+ password = Optional(str)
+ start_date = Optional(str)
+ expiry_date = Optional(str)
+
+
+class Article(db.Entity):
+ _table_ = "article" # table name
+ article_id = PrimaryKey(int, auto=True)
+ text = Optional(str)
+ source = Optional(str)
+ date = Optional(str)
+ level = Optional(str)
+ question = Optional(str)
+
+
+db.generate_mapping(create_tables=True) # must mapping after class declaration
+
+
+if __name__ == "__main__":
+ with db_session:
+ print(Article[2].text) # test get article which id=2 text content
From e2b165ada84b7ed4827e2f211f4aa55d9218a009 Mon Sep 17 00:00:00 2001
From: Awoodwhale
Date: Mon, 20 Mar 2023 20:11:37 +0800
Subject: [PATCH 24/70] fix: add url 'admin' into banned url list
---
app/Login.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/Login.py b/app/Login.py
index 8e0030b..f914359 100644
--- a/app/Login.py
+++ b/app/Login.py
@@ -98,7 +98,7 @@ class UserName:
for c in self.username: # a user name must not include special characters, except non-leading periods or underscores
if c in string.punctuation and c is not '.' and c is not '_':
return f'{c} is not allowed in the user name.'
- if self.username in ['signup', 'login', 'logout', 'reset', 'mark', 'back', 'unfamiliar', 'familiar', 'del']:
+ if self.username in ['signup', 'login', 'logout', 'reset', 'mark', 'back', 'unfamiliar', 'familiar', 'del', "admin"]:
return 'You used a restricted word as your user name. Please come up with a better one.'
return 'OK'
From 13d8977636f9fe41b67a06d403ce03cecd630165 Mon Sep 17 00:00:00 2001
From: Awoodwhale
Date: Mon, 20 Mar 2023 20:15:58 +0800
Subject: [PATCH 25/70] fix: set specific management displays for admin
---
app/templates/userpage_get.html | 7 ++-----
app/user_service.py | 3 ++-
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index fbe281d..efb55da 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -37,14 +37,11 @@
English Pal for {{ username }}
-<<<<<<< HEAD
+ {% if username == admin_name%}
管理
+ {% endif %}
退出
重设密码
-=======
- 退出
- 重设密码
->>>>>>> master
{{ flashed_messages|safe }}
diff --git a/app/user_service.py b/app/user_service.py
index 2d10404..215f0e5 100644
--- a/app/user_service.py
+++ b/app/user_service.py
@@ -1,5 +1,5 @@
from datetime import datetime
-
+from admin_service import ADMIN_NAME
from flask import *
# from app import Yaml
@@ -131,6 +131,7 @@ def userpage(username):
for x in lst3:
words += x[0] + ' '
return render_template('userpage_get.html',
+ admin_name=ADMIN_NAME,
username=username,
session=session,
flashed_messages=get_flashed_messages_if_any(),
From ade10e58431e141ef576fc77d37286ddc73988a9 Mon Sep 17 00:00:00 2001
From: Awoodwhale
Date: Mon, 20 Mar 2023 20:16:48 +0800
Subject: [PATCH 26/70] feat: add admin_service blueprint
---
app/admin_service.py | 118 +++++++++++++++++++++
app/main.py | 77 +-------------
app/templates/admin_index.html | 184 +++++++++++++++++----------------
3 files changed, 216 insertions(+), 163 deletions(-)
create mode 100644 app/admin_service.py
diff --git a/app/admin_service.py b/app/admin_service.py
new file mode 100644
index 0000000..87d2610
--- /dev/null
+++ b/app/admin_service.py
@@ -0,0 +1,118 @@
+from flask import *
+from model import *
+from pony.orm import *
+from Yaml import yml
+from Login import md5
+from datetime import datetime
+
+# ? from difficulty import text_difficulty_level
+
+ADMIN_NAME = "114514" # unique admin name
+_cur_page = 1 # current article page
+_page_size = 5 # article sizes per page
+adminService = Blueprint("admin_service", __name__)
+
+
+@adminService.route("/admin", methods=["GET", "POST"])
+def admin():
+ global _cur_page, _page_size
+ # 未登录,跳转到未登录界面
+ if not session.get("logged_in"):
+ return render_template("not_login.html")
+
+ # 获取session里的用户名
+ username = session.get("username")
+ if username != ADMIN_NAME:
+ return "You are not admin!"
+
+ article_len = get_articles_len()
+ try:
+ _page_size = min(int(request.args.get("size", 5)), article_len)
+ if _page_size <= 0:
+ raise ZeroDivisionError
+ _cur_page = min(int(request.args.get("page", 1)), article_len // _page_size)
+ except ValueError:
+ return "page parmas must be int!"
+ except ZeroDivisionError:
+ return "page size must bigger than zero"
+
+ context = {
+ "text_len": article_len,
+ "page_size": _page_size,
+ "cur_page": _cur_page,
+ "text_list": get_page_articles(_cur_page, _page_size),
+ "user_list": get_users(),
+ "username": username,
+ "yml": yml,
+ }
+
+ def _update_context():
+ article_len = get_articles_len()
+ context["text_len"] = article_len
+ context["text_list"] = get_page_articles(_cur_page, _page_size)
+
+ if request.method == "GET":
+ if delete_id := int(request.args.get("delete_id", 0)): # delete article
+ delete_article(delete_id)
+ _update_context()
+ else:
+ data = request.form
+ content = data.get("content", "")
+ source = data.get("source", "")
+ question = data.get("question", "")
+ username = data.get("username", "")
+ if content:
+ add_article(content, source, question)
+ _update_context()
+ if username:
+ update_user_password(username)
+
+ return render_template("admin_index.html", **context)
+
+
+def add_article(content, source="manual_input", question="No question"):
+ with db_session:
+ # add one atricle to sqlite
+ Article(
+ text=content,
+ source=source,
+ date=datetime.now().strftime("%-d %b %Y"), # format style of `5 Oct 2022`
+ level="1",
+ question=question,
+ )
+ # ? There is a question that:
+ # ? How can i get one article level?
+ # ? I try to use the function `text_difficulty_level(content,{"test":1})`
+ # ? However, i lose one dict parma from pickle
+ # ? So I temporarily fixed the level to 1
+
+
+def delete_article(article_id):
+ article_id &= 0xFFFFFFFF # max 32 bits
+ with db_session:
+ if article := Article.select(article_id=article_id):
+ article.first().delete()
+
+
+def get_articles_len():
+ with db_session:
+ return len(Article.select()[:])
+
+
+def get_page_articles(num, size):
+ with db_session:
+ return [
+ x
+ for x in Article.select().order_by(desc(Article.article_id)).page(num, size)
+ ]
+
+
+def get_users():
+ with db_session:
+ return User.select()[:]
+
+
+def update_user_password(username, password="123456"):
+ with db_session:
+ if user := User.select(name=username).first():
+ user.password = md5(username + password)
diff --git a/app/main.py b/app/main.py
index bcbd3f8..2af57e3 100644
--- a/app/main.py
+++ b/app/main.py
@@ -5,24 +5,24 @@
# Copyright 2019 (C) Hui Lan
# Written permission must be obtained from the author for commercial uses.
###########################################################################
-from datetime import datetime
from flask import escape
from Login import *
from Article import *
import Yaml
from user_service import userService
from account_service import accountService
+from admin_service import adminService
app = Flask(__name__)
app.secret_key = 'lunch.time!'
# 将蓝图注册到Lab app
app.register_blueprint(userService)
app.register_blueprint(accountService)
+app.register_blueprint(adminService)
path_prefix = '/var/www/wordfreq/wordfreq/'
path_prefix = './' # comment this line in deployment
-
def get_random_image(path):
'''
返回随机图
@@ -102,79 +102,6 @@ def mainpage():
d_len=d_len, lst=lst, yml=Yaml.yml)
-def insert_article(content, source='manual_input', level=5, question=''):
- sql = f"INSERT into article (text,source, date, level, question) VALUES " \
- f"('{content}','{source}','{datetime.now().strftime('%Y-%m-%d')}', '{level}', '{question}');"
- print(sql)
- rq = RecordQuery('./static/wordfreqapp.db')
- rq.instructions(sql)
- rq.do()
-
-
-def get_articles():
- sql = f"SELECT * from article order by -article_id;"
- rq = RecordQuery('./static/wordfreqapp.db')
- rq.instructions(sql)
- rq.do()
- result = rq.get_results()
- return result
-
-
-def get_users():
- sql = f"SELECT * from user;"
- rq = RecordQuery('./static/wordfreqapp.db')
- rq.instructions(sql)
- rq.do()
- result = rq.get_results()
- return result
-
-
-def update_user_password(username, password='123456'):
- password = md5(username + password)
- sql = f"UPDATE user SET password='{password}' where name='{username}';"
- rq = RecordQuery('./static/wordfreqapp.db')
- rq.instructions(sql)
- rq.do()
-
-
-@app.route("/admin", methods=['GET', 'POST'])
-def admin():
- '''
- '''
- # 未登录,跳转到未登录界面
- if not session.get('logged_in'):
- return render_template('not_login.html')
-
- # 获取session里的用户名
- username = session.get('username')
-
- context = {
- # 'user': request.user,
- 'text_list': get_articles(),
- 'user_list': get_users(),
- 'username': username
- }
- if request.method == 'GET':
- return render_template('admin_index.html', **context)
- else:
- data = request.form
- content = data.get('content')
- source = data.get('source', '')
- question = data.get('question', '')
- username = data.get('username')
- if content:
- insert_article(
- content=content,
- source=source,
- question=question
- )
- context['text_list'] = get_articles()
- if username:
- update_user_password(username)
- return render_template('admin_index.html', **context)
-
-
-
if __name__ == '__main__':
'''
运行程序
diff --git a/app/templates/admin_index.html b/app/templates/admin_index.html
index be88556..03d6ee4 100644
--- a/app/templates/admin_index.html
+++ b/app/templates/admin_index.html
@@ -1,112 +1,120 @@
-
+
+
-
+
+
+
+ {{ yml['header'] | safe }}
+ {% if yml['css']['item'] %}
+ {% for css in yml['css']['item'] %}
+
+ {% endfor %}
+ {% endif %}
+ {% if yml['js']['head'] %}
+ {% for js in yml['js']['head'] %}
+
+ {% endfor %}
+ {% endif %}
-