修改database_tools.py中讲义生成功能的小bug

This commit is contained in:
wangweiye7840 2023-12-15 12:53:17 +08:00
parent 382c27be06
commit 0d07076f83
1 changed files with 6 additions and 7 deletions

View File

@ -724,8 +724,9 @@ def GenerateValueColorCode(matchobj): # 生成三位小数代表的颜色方框(
def StudentsGetAfterContent(id,prodict,answered,spaceflag): #生成学生版讲义后的答案及空格, answered表示有无答案, spaceflag表示有无空格
string = ""
if answered:
string += "答案: \\textcolor{red}{%s}\n\n"%(prodict[id]["ans"] if prodict[id]["ans"] != "" else "暂无答案")
if "ans" in prodict[id]:
if answered:
string += "答案: \\textcolor{red}{%s}\n\n"%(prodict[id]["ans"] if prodict[id]["ans"] != "" else "暂无答案")
if spaceflag:
if "space" in prodict[id]:
if prodict[id]["space"] != "":
@ -1258,24 +1259,22 @@ def select_grade_from_pro_dict(prodict,grades):
return adict
def GenerateSingleLessonNote(id,notesdict,metadict,templatepath,outputfilepath,consecutivenumbering = False, answered = False): #20231215版讲义生成
notetitle = id+ r" \ " + notesdict["notes"][id]["name"]
notetitle = id + r" \ " + notesdict["notes"][id]["name"]
structure = notesdict["structures"][id[0].upper()]
note_contents = notesdict["notes"][id]
print(structure)
output = ""
sections_list = []
problems_list = []
for key in structure:
print(structure[key])
if not len(note_contents[key]) == 0:
sections_list.append(key)
problems_list.append(",".join(note_contents[key]))
rawoutput = GenerateStudentBodyString(problems=problems_list,secidontitles=sections_list,pro_dict=metadict,consecutivenumbering= False, answered= False, spaceflag = True)
rawoutput = GenerateStudentBodyString(problems=problems_list,sectiontitles=sections_list,pro_dict=metadict,consecutivenumbering= consecutivenumbering, answered= answered, spaceflag = True)
paragraphs = [p for p in rawoutput.split("\\section") if not p.strip() == ""]
for item in paragraphs:
sectionkey, content = re.findall(r"\{([\S]*)\}\n([\S\s]*)$",item)[0]
output += "\\section{" + structure[sectionkey]["name"] + "}\n\n"
if not structure[sectionkey]["spaceflag"]:
if not structure[sectionkey]["spaceflag"] or answered:
content = re.sub(r"\\vspace[\*]?\{[\S]*\}","\n",content)
output += content + "\n\n"