讲义结构与内容录入 功能适配 讲义内容上传至mariadb的情形
This commit is contained in:
parent
da99fcb6e3
commit
f9fa43bb77
|
|
@ -298,7 +298,7 @@ def generate_classid(string): #返回班级列表
|
|||
|
||||
|
||||
def generate_id_set(string,*thedict): #除了生成题号列表外, 还能根据首字母生成基础知识编号列表或课时目标列表
|
||||
string = RefinePunctuations(string)
|
||||
string = RefinePunctuations(string).upper()
|
||||
if re.findall(r"[BXK]",string) == []:
|
||||
if thedict == ():
|
||||
return generate_number_set(string)
|
||||
|
|
@ -3362,15 +3362,16 @@ def generateUsagedetail(zipfilepath,tempdir,answersheetseekingpath,statsfilename
|
|||
|
||||
|
||||
def load_notes_dict_from_mariadb(cursor): #从mariadb获取讲义列表
|
||||
sql = "SELECT nid,name,filename,structure FROM notes WHERE NOT obsolete;"
|
||||
sql = "SELECT nid,name,filename,structure,remarks FROM notes WHERE NOT obsolete;"
|
||||
cursor.execute(sql)
|
||||
ret = cursor.fetchall()
|
||||
notes_dict = {}
|
||||
for nid,name,filename,structure in ret:
|
||||
for nid,name,filename,structure,remarks in ret:
|
||||
temp_dict = json.loads(structure)
|
||||
notes_dict[nid] = {'id':nid,'name':name,'filename':filename}
|
||||
for key in temp_dict:
|
||||
notes_dict[nid][key] = temp_dict[key]
|
||||
# notes_dict[nid]["remarks"] = "" if remarks is None else remarks
|
||||
return notes_dict
|
||||
|
||||
def load_structures_dict_from_mariadb(cursor): # 从mariadb获取讲义结构列表
|
||||
|
|
|
|||
|
|
@ -68,21 +68,18 @@ class MyWindow_jglr(QWidget,Ui_Form):
|
|||
val = (GetDate(),GetTime(),get_git_username(),"添加新讲义结构",self.prefix[0:5])
|
||||
mycursor.execute(sql,val)
|
||||
mydb.commit()
|
||||
####20240616到这里
|
||||
# notes_dict["structures"][self.prefix[0]] = new_struct_dict.copy()
|
||||
# save_dict(notes_dict,jsonfile)
|
||||
else:
|
||||
pass
|
||||
else:
|
||||
numberlist = []
|
||||
for id in notes_dict["notes"]:
|
||||
if self.prefix in id:
|
||||
numberlist.append(id[-2:])
|
||||
for existing_nid in notes_dict:
|
||||
if self.prefix in existing_nid:
|
||||
numberlist.append(existing_nid[-2:])
|
||||
print("该分类下已有材料编号: "+generate_exp(numberlist))
|
||||
pid = self.prefix + input("请输入新材料编号(两位数):")
|
||||
while pid in notes_dict["notes"]:
|
||||
nid = self.prefix + input("请输入新材料编号(两位数):")
|
||||
while nid in notes_dict:
|
||||
print("编号重复, 请重新输入.")
|
||||
pid = self.prefix + input("请输入新材料编号(两位数):")
|
||||
nid = self.prefix + input("请输入新材料编号(两位数):")
|
||||
name = input("请输入材料名称:")
|
||||
filenameraw = input("生成的文件名和材料名称是否一致?([Y]/如果不一致请输入文件名):")
|
||||
if filenameraw.upper() == "Y" or len(filenameraw.strip()) == 0:
|
||||
|
|
@ -90,26 +87,35 @@ class MyWindow_jglr(QWidget,Ui_Form):
|
|||
else:
|
||||
filename = filenameraw
|
||||
new_note_dict = {
|
||||
"id": pid,
|
||||
"nid": nid,
|
||||
"name": name,
|
||||
"filename": filename
|
||||
}
|
||||
structure = notes_dict['structures'][self.prefix[0]]['structure']
|
||||
new_note_dict_structure = {}
|
||||
structure = structure_dict[self.prefix[0:5]]['structure']
|
||||
print(f"此类材料共有 {len(structure)} 个部分, 分别是:")
|
||||
for p in structure:
|
||||
print(f"{p}: {structure[p]['name']}")
|
||||
new_note_dict[p] = []
|
||||
new_note_dict_structure[p] = []
|
||||
for p in structure:
|
||||
rawdata = input(f"现在输入 {p}: {structure[p]['name']} 部分的内容编号:")
|
||||
rawdata = RefinePunctuations(rawdata)
|
||||
rawdata = re.sub(r"[^BXK\d:,]","",rawdata)
|
||||
if re.findall(r"\d",rawdata) == []:
|
||||
new_note_dict[p] = []
|
||||
else:
|
||||
new_note_dict[p] = generate_id_set(rawdata)
|
||||
print(f"{p}: {new_note_dict[p]}")
|
||||
notes_dict["notes"][pid] = new_note_dict.copy()
|
||||
notes_dict["notes"] = SortDict(notes_dict["notes"])
|
||||
save_dict(notes_dict,jsonfile)
|
||||
temp_dict = new_note_dict.copy()
|
||||
for key in ["nid","name","filename"]:
|
||||
temp_dict.pop(key)
|
||||
sql = "INSERT INTO notes (nid,name,filename,structure) VALUES (%s,%s,%s,%s);"
|
||||
val = (nid,name,filename,json.dumps(temp_dict,ensure_ascii = False))
|
||||
mycursor.execute(sql,val)
|
||||
sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);"
|
||||
val = (GetDate(),GetTime(),get_git_username(),"添加新讲义内容",self.prefix)
|
||||
mycursor.execute(sql,val)
|
||||
mydb.commit()
|
||||
print("处理完成")
|
||||
mydb.close()
|
||||
|
||||
|
|
|
|||
Reference in New Issue