添加关联题目 功能完成

This commit is contained in:
weiye.wang 2024-04-15 06:48:07 +08:00
parent 12e54a7759
commit ca58acf66b
1 changed files with 28 additions and 1 deletions

View File

@ -400,7 +400,34 @@ def CreateNewProblem(id,content,origin,dict,editor): # 构建一道新题目的
return NewProblem # 返回一道新题目的字典, 已赋新的ID, 内容, 来源和编辑者
def AddRelatedProblemToDB(id,content,oid,editor):
pass
mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest")
mycursor = mydb.cursor()
id = str(id).zfill(6)
if "blank" in content:
genre = "填空题"
space = ""
elif "bracket" in content:
genre = "选择题"
space = ""
else:
genre = "解答题"
space = "4em"
origin_json = {"来源": "改编题目", "前序": str(oid).zfill(6)}
origin = json.dumps(origin_json,ensure_ascii=False)
sql = "INSERT INTO problems (ID,content,genre,origin,space) VALUE (%s,%s,%s,%s,%s);"
val = (id,content,genre,origin,space)
mycursor.execute(sql,val)
sql = "INSERT INTO edit_history (ID,date,editor) VALUE (%s,%s,%s);"
val = (id,GetDate(),editor.strip())
mycursor.execute(sql,val)
sql = "INSERT INTO related (ID,RELATED_ID) VALUE (%s,%s);"
val = (id, oid)
if id > oid:
val = (oid, id)
mycursor.execute(sql,val)
mydb.commit()
mydb.close()
return id
def AddProblemstoDict2024(startingid,raworigin,problems,editor,indexed): #将来自GenerateProblemListFromString的列表中的题目添加到thedict字典, 返回题号列表(包括用老题号替代的题目)
mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest")