From 0d07076f8312b83e25100351c13514db0002f398 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Fri, 15 Dec 2023 12:53:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9database=5Ftools.py=E4=B8=AD?= =?UTF-8?q?=E8=AE=B2=E4=B9=89=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD=E7=9A=84?= =?UTF-8?q?=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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"