备注信息收集 增加避免重复的校验
This commit is contained in:
parent
8010b6db4e
commit
3dc70a2756
|
|
@ -69,19 +69,28 @@ def submit_remarks():
|
||||||
# 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 = "tikutest")
|
||||||
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku")
|
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku")
|
||||||
mycursor = mydb.cursor()
|
mycursor = mydb.cursor()
|
||||||
sql = f"INSERT INTO remarks SET ID = %s, date = %s, remark_content = %s;"
|
sql = f"SELECT * FROM remarks WHERE ID = %s and remark_content = %s;"
|
||||||
val = (id,date,f"({category}){remarks}")
|
val = (id,f"({category}){remarks}")
|
||||||
|
print(f"({category}){remarks}")
|
||||||
mycursor.execute(sql,val)
|
mycursor.execute(sql,val)
|
||||||
ip_address = request.headers.get('X-Forwarded-For', request.remote_addr)
|
ret = mycursor.fetchall()
|
||||||
# 如果 X-Forwarded-For 头存在多个 IP 地址,则取第一个
|
if len(ret) == 0:
|
||||||
if ',' in ip_address:
|
sql = f"INSERT INTO remarks SET ID = %s, date = %s, remark_content = %s;"
|
||||||
ip_address = ip_address.split(',')[0]
|
val = (id,date,f"({category}){remarks}")
|
||||||
sql = "INSERT INTO logs (DATE,TIME,username,ID,action,db_content) VALUE (%s,%s,%s,%s,%s,%s);"
|
mycursor.execute(sql,val)
|
||||||
val = (GetDate(),GetTime(),f"{username} at {ip_address}",id,f"网页新增备注",f"({category}){remarks}")
|
ip_address = request.headers.get('X-Forwarded-For', request.remote_addr)
|
||||||
mycursor.execute(sql,val)
|
# 如果 X-Forwarded-For 头存在多个 IP 地址,则取第一个
|
||||||
mydb.commit()
|
if ',' in ip_address:
|
||||||
mydb.close()
|
ip_address = ip_address.split(',')[0]
|
||||||
return render_template('show_remarks.html', category=category, remarks=remarks)
|
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)
|
||||||
|
else:
|
||||||
|
mydb.close()
|
||||||
|
return f"已有备注 ({category}){remarks}"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Reference in New Issue