批量收录新题时有重复题目将回滚数据库并在终端显示信息
This commit is contained in:
parent
ab8e53dce2
commit
5036014113
|
|
@ -542,6 +542,7 @@ def AddRelatedProblemToDB(id,content,oid,editor,database):
|
||||||
def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,cursor): #将来自GenerateProblemListFromString的列表中的题目添加到thedict字典, 返回题号列表(包括用老题号替代的题目)
|
def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,cursor): #将来自GenerateProblemListFromString的列表中的题目添加到thedict字典, 返回题号列表(包括用老题号替代的题目)
|
||||||
mycursor = cursor
|
mycursor = cursor
|
||||||
idlist = []
|
idlist = []
|
||||||
|
problemlist = []
|
||||||
id = int(startingid)
|
id = int(startingid)
|
||||||
currentsuffix = problems[0][1]
|
currentsuffix = problems[0][1]
|
||||||
problemindex = 0
|
problemindex = 0
|
||||||
|
|
@ -549,6 +550,7 @@ def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,c
|
||||||
try:
|
try:
|
||||||
p, suffix, meta = p_and_suffix_and_meta
|
p, suffix, meta = p_and_suffix_and_meta
|
||||||
p = re.sub(r"\n\s+","\n",p)
|
p = re.sub(r"\n\s+","\n",p)
|
||||||
|
problemlist.append(p)
|
||||||
pid = str(id).zfill(6)
|
pid = str(id).zfill(6)
|
||||||
if suffix == currentsuffix:
|
if suffix == currentsuffix:
|
||||||
problemindex += 1
|
problemindex += 1
|
||||||
|
|
@ -610,7 +612,7 @@ def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,c
|
||||||
print(f"错误的题目: {p_and_suffix_and_meta}")
|
print(f"错误的题目: {p_and_suffix_and_meta}")
|
||||||
idlist = []
|
idlist = []
|
||||||
break
|
break
|
||||||
return idlist
|
return (idlist,problemlist)
|
||||||
|
|
||||||
def CreateIDLinks(old_id_list,new_id_list): #建立已有id和新id之间的联系, thedict为可选, 选中的话即为当前字典, 会从new_id_list中排除当前字典中有的项
|
def CreateIDLinks(old_id_list,new_id_list): #建立已有id和新id之间的联系, thedict为可选, 选中的话即为当前字典, 会从new_id_list中排除当前字典中有的项
|
||||||
if len(old_id_list)>len(new_id_list):
|
if len(old_id_list)>len(new_id_list):
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ class MyWindow_bdsl(QWidget,Ui_Form):
|
||||||
self.pushButton_step2.clicked.connect(self.execstep2)
|
self.pushButton_step2.clicked.connect(self.execstep2)
|
||||||
self.pushButton_commit.clicked.connect(self.commitchange)
|
self.pushButton_commit.clicked.connect(self.commitchange)
|
||||||
self.plainTextEdit_compared.textChanged.connect(self.commitdisable)
|
self.plainTextEdit_compared.textChanged.connect(self.commitdisable)
|
||||||
|
self.problemstoimport = []
|
||||||
def togglesuffix(self):
|
def togglesuffix(self):
|
||||||
self.suffix_checked = self.checkBox_suffix.isChecked()
|
self.suffix_checked = self.checkBox_suffix.isChecked()
|
||||||
if self.suffix_checked:
|
if self.suffix_checked:
|
||||||
|
|
@ -99,7 +100,15 @@ class MyWindow_bdsl(QWidget,Ui_Form):
|
||||||
self.db = connect(hostname = db_host, port= db_port, username= db_user, pwd = db_pwd, db= self.database_name)
|
self.db = connect(hostname = db_host, port= db_port, username= db_user, pwd = db_pwd, db= self.database_name)
|
||||||
self.cursor = self.db.cursor()
|
self.cursor = self.db.cursor()
|
||||||
rolled_back = False
|
rolled_back = False
|
||||||
idlist = AddProblemstoDict2024nocommit(nextspareid,raworigin,problems,editor,Indexed,self.cursor)
|
idlist,newproblemlist = AddProblemstoDict2024nocommit(nextspareid,raworigin,problems,editor,Indexed,self.cursor)
|
||||||
|
for p in newproblemlist:
|
||||||
|
if p in self.problemstoimport:
|
||||||
|
print("有重复导入的题目, 改变已回滚!!!\n"*5)
|
||||||
|
self.db.rollback()
|
||||||
|
rolled_back = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.problemstoimport.append(p)
|
||||||
if idlist == []:
|
if idlist == []:
|
||||||
print("有错误, 改变已回滚.")
|
print("有错误, 改变已回滚.")
|
||||||
self.db.rollback()
|
self.db.rollback()
|
||||||
|
|
@ -108,6 +117,8 @@ class MyWindow_bdsl(QWidget,Ui_Form):
|
||||||
AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath)
|
AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath)
|
||||||
os.system(f"code {idlistpath}")
|
os.system(f"code {idlistpath}")
|
||||||
self.pushButton_commit.setEnabled(True)
|
self.pushButton_commit.setEnabled(True)
|
||||||
|
else:
|
||||||
|
self.pushButton_commit.setDisabled(True)
|
||||||
def commitdisable(self):
|
def commitdisable(self):
|
||||||
self.pushButton_commit.setDisabled(True)
|
self.pushButton_commit.setDisabled(True)
|
||||||
|
|
||||||
|
|
|
||||||
Reference in New Issue