diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index c4bbebc9..d447447a 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -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"