备注信息收集完成

This commit is contained in:
weiye.wang 2024-05-12 20:05:53 +08:00
parent 55d90e48a8
commit de437a92c2
2 changed files with 34 additions and 26 deletions

View File

@ -1,25 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Save Data</title>
<title>登记备注</title>
</head>
<body>
<form method="POST">
<label for="text1">题号:</label>
<input type="text" id="text1" name="text1"><br><br>
<label for="text2">备注内容:</label>
<input type="text" id="text2" name="text2"><br><br>
<label for="category">Category:</label>
<select id="category" name="category">
<option value="主要错误">主要错误</option>
<option value="主要错因">主要错因</option>
<option value="批改建议">批改建议</option>
<option value="其它">其它</option>
</select><br><br>
<input type="submit" value="Save Data">
<h1>登记备注</h1>
<form action="/show_image" method="POST">
<label for="question_number">姓名:</label>
<input type="text" id="username" name = "username">
<br>
<label for="question_number">题号:</label>
<input type="text" id="question_number" name="question_number">
<input type="submit" value="提交">
</form>
</body>
</html>

View File

@ -6,11 +6,16 @@ app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
return render_template('remarkindex.html')
@app.route('/show_image', methods=['POST'])
def show_image():
if request.method == 'POST':
global id,username
username = request.form['username'].strip()
print(username)
if len(username) <= 1:
return "姓名有误."
id = request.form['question_number'].zfill(6)
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku")
mycursor = mydb.cursor()
@ -21,7 +26,7 @@ def show_image():
sql = "SELECT date,remark_content FROM remarks WHERE ID = %s;"
mycursor.execute(sql,val)
remark_list = sorted(mycursor.fetchall(),key=lambda item:item[0],reverse=True)
print(remark_list)
# print(remark_list)
mydb.close()
content_hash = hashlib.sha256(content.encode("utf8")).hexdigest()
# print(content_hash,type(content_hash))
@ -59,14 +64,25 @@ def show_image():
@app.route('/submit_remarks', methods=['POST'])
def submit_remarks():
category = request.form['category']
remarks = request.form['remarks']
# date = GetDate()
# mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku")
# mycursor = mydb.cursor()
# mydb.close()
remarks = request.form['remarks'].repalce("\n"," ").strip()
date = GetDate()
# mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tikutest")
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku")
mycursor = mydb.cursor()
sql = f"INSERT INTO remarks SET ID = %s, date = %s, remark_content = %s;"
val = (id,date,f"({category}){remarks}")
mycursor.execute(sql,val)
ip_address = request.headers.get('X-Forwarded-For', request.remote_addr)
# 如果 X-Forwarded-For 头存在多个 IP 地址,则取第一个
if ',' in ip_address:
ip_address = ip_address.split(',')[0]
sql = "INSERT INTO logs (DATE,TIME,username,ID,action,db_content) VALUE (%s,%s,%s,%s,%s,%s);"
val = (GetDate(),GetTime(),f"{username} at {ip_address}",id,f"网页新增备注",f"({category}){remarks}")
mycursor.execute(sql,val)
mydb.commit()
mydb.close()
return render_template('show_remarks.html', category=category, remarks=remarks)
if __name__ == '__main__':
app.run(debug=True)
app.run(host = "0.0.0.0", port = 25433)