From 45a342cfe247fe0d3e7698862e8099e89ea5e017 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Tue, 16 Apr 2024 22:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE=E5=86=85=E5=AE=B9=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD=20=E5=9C=A8?= =?UTF-8?q?=E5=B7=A5=E5=85=B7v3=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v3/Ui_题目内容直接编辑.py | 84 +++++++++++++++ 工具v3/database_tools_2.py | 11 ++ 工具v3/工具面板.py | 2 +- 工具v3/题目内容直接编辑.py | 194 ++++++++++++++++++++++++++++++++++ 工具v3/题目内容直接编辑.ui | 174 ++++++++++++++++++++++++++++++ 5 files changed, 464 insertions(+), 1 deletion(-) create mode 100644 工具v3/Ui_题目内容直接编辑.py create mode 100644 工具v3/题目内容直接编辑.py create mode 100644 工具v3/题目内容直接编辑.ui diff --git a/工具v3/Ui_题目内容直接编辑.py b/工具v3/Ui_题目内容直接编辑.py new file mode 100644 index 00000000..522fb597 --- /dev/null +++ b/工具v3/Ui_题目内容直接编辑.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file '题目内容直接编辑.ui' +## +## Created by: Qt User Interface Compiler version 6.6.2 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QLabel, QLineEdit, QPlainTextEdit, + QPushButton, QSizePolicy, QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(641, 245) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(10, 10, 54, 16)) + self.lineEdit_ID = QLineEdit(Form) + self.lineEdit_ID.setObjectName(u"lineEdit_ID") + self.lineEdit_ID.setGeometry(QRect(10, 30, 71, 20)) + self.pushButton_content = QPushButton(Form) + self.pushButton_content.setObjectName(u"pushButton_content") + self.pushButton_content.setGeometry(QRect(10, 60, 75, 24)) + self.pushButton_genre = QPushButton(Form) + self.pushButton_genre.setObjectName(u"pushButton_genre") + self.pushButton_genre.setGeometry(QRect(10, 90, 75, 24)) + self.pushButton_ans = QPushButton(Form) + self.pushButton_ans.setObjectName(u"pushButton_ans") + self.pushButton_ans.setGeometry(QRect(10, 120, 75, 24)) + self.pushButton_solution = QPushButton(Form) + self.pushButton_solution.setObjectName(u"pushButton_solution") + self.pushButton_solution.setGeometry(QRect(10, 150, 75, 24)) + self.pushButton_origin = QPushButton(Form) + self.pushButton_origin.setObjectName(u"pushButton_origin") + self.pushButton_origin.setGeometry(QRect(10, 180, 75, 24)) + self.pushButton_remarks = QPushButton(Form) + self.pushButton_remarks.setObjectName(u"pushButton_remarks") + self.pushButton_remarks.setGeometry(QRect(10, 210, 75, 24)) + self.label_2 = QLabel(Form) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(90, 10, 191, 16)) + self.plainTextEdit_toedit = QPlainTextEdit(Form) + self.plainTextEdit_toedit.setObjectName(u"plainTextEdit_toedit") + self.plainTextEdit_toedit.setGeometry(QRect(90, 30, 471, 201)) + self.pushButton_exec = QPushButton(Form) + self.pushButton_exec.setObjectName(u"pushButton_exec") + self.pushButton_exec.setGeometry(QRect(570, 30, 61, 91)) + self.pushButton_tocommit = QPushButton(Form) + self.pushButton_tocommit.setObjectName(u"pushButton_tocommit") + self.pushButton_tocommit.setGeometry(QRect(570, 130, 61, 101)) + font = QFont() + font.setBold(True) + self.pushButton_tocommit.setFont(font) + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"\u9898\u5e93\u5185\u5bb9\u76f4\u63a5\u7f16\u8f91", None)) + self.label.setText(QCoreApplication.translate("Form", u"\u9898\u53f7", None)) + self.pushButton_content.setText(QCoreApplication.translate("Form", u"\u9898\u76ee\u5185\u5bb9", None)) + self.pushButton_genre.setText(QCoreApplication.translate("Form", u"\u7c7b\u578b", None)) + self.pushButton_ans.setText(QCoreApplication.translate("Form", u"\u7b54\u6848", None)) + self.pushButton_solution.setText(QCoreApplication.translate("Form", u"\u89e3\u7b54", None)) + self.pushButton_origin.setText(QCoreApplication.translate("Form", u"\u6765\u6e90", None)) + self.pushButton_remarks.setText(QCoreApplication.translate("Form", u"\u5907\u6ce8\u5217\u8868", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"\u9898\u53f7\u4e3a \u7684 \u5b57\u6bb5", None)) + self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u4fee\u6539", None)) + self.pushButton_tocommit.setText(QCoreApplication.translate("Form", u"\u63d0\u4ea4", None)) + # retranslateUi + diff --git a/工具v3/database_tools_2.py b/工具v3/database_tools_2.py index 306a1e32..348251a1 100644 --- a/工具v3/database_tools_2.py +++ b/工具v3/database_tools_2.py @@ -2585,6 +2585,17 @@ def getAllIDsExp(obsincluded = True): #获取题库中所有题目的id(含:,) idlist = [ret[0] for ret in mycursor.fetchall()] return generate_exp(idlist) +def parseRemark(string): #从一行remark字符串中分出日期和内容, 返回 日期,内容 元组 + remark_raw = string.replace(r"\\","").strip() + date_raw_list = re.findall(r"^\({0,1}\d{8}\){0,1}",remark_raw) + if len(date_raw_list) > 0: + date_raw = date_raw_list[0] + date = re.sub(r"[\(\)]","",date_raw) + remark = re.sub(date,"",remark_raw).strip().replace("()","") + else: + date = "00000000" + remark = remark_raw + return date,remark if __name__ == "__main__": diff --git a/工具v3/工具面板.py b/工具v3/工具面板.py index 049d3226..56ef18cf 100644 --- a/工具v3/工具面板.py +++ b/工具v3/工具面板.py @@ -31,7 +31,7 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.action_plsl.triggered.connect(lambda: run_command("批量收录题目",[]))#已完成 self.action_tjgl.triggered.connect(lambda: run_command("添加关联题目",[]))#已完成 self.action_tjzd.triggered.connect(lambda: run_command("修改metadata",["文本文件/metadata.txt"]))#已完成 - self.action_bjtm.triggered.connect(lambda: run_command("编辑题目信息",[]))#已完成 + self.action_bjtm.triggered.connect(lambda: run_command("题目内容直接编辑",[]))#已完成 self.action_xxdr.triggered.connect(lambda: run_command("获取小闲平台使用数据new",[]))#已完成 self.action_sddr.triggered.connect(lambda: run_command("手动统计结果导入",["临时文件/手动统计结果.txt"]))#已完成 self.action_tkdr.triggered.connect(lambda: run_command("统考数据导入",[]))#已完成 diff --git a/工具v3/题目内容直接编辑.py b/工具v3/题目内容直接编辑.py new file mode 100644 index 00000000..cc266812 --- /dev/null +++ b/工具v3/题目内容直接编辑.py @@ -0,0 +1,194 @@ +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog +from Ui_题目内容直接编辑 import Ui_Form +from database_tools_2 import * + +class MyWindow(QWidget,Ui_Form): + def __init__(self): + super().__init__() + self.setupUi(self) + self.bind() + + def bind(self): + self.lineEdit_ID.textChanged.connect(self.getID) + self.pushButton_content.clicked.connect(self.showcontent) + self.pushButton_genre.clicked.connect(self.showgenre) + self.pushButton_ans.clicked.connect(self.showans) + self.pushButton_solution.clicked.connect(self.showsolution) + self.pushButton_origin.clicked.connect(self.showorigin) + self.pushButton_remarks.clicked.connect(self.showremarks) + self.pushButton_exec.clicked.connect(self.exec) + self.pushButton_tocommit.clicked.connect(self.tocommit) + self.db = connect(hostname = "wwylss.synology.me", port = "13306", username = "tikuuser", pwd = "Kjmathds_2024", db = "tikutest") + self.cursor = self.db.cursor() + self.changedids = [] + def getID(self): + self.ID = self.lineEdit_ID.text().zfill(6) + def showcontent(self): + self.field = "题目内容" + self.label_2.setText(f"题号 {self.lineEdit_ID.text()} 的 {self.field} 字段") + sql = "SELECT content FROM problems WHERE ID = (%s);" + val = (self.lineEdit_ID.text().zfill(6),) + self.cursor.execute(sql,val) + ret = self.cursor.fetchall() + if ret[0][0] is None: + self.originalcontent = "" + else: + self.originalcontent = ret[0][0].strip() + self.plainTextEdit_toedit.setPlainText(self.originalcontent) + def showgenre(self): + self.field = "类型" + self.label_2.setText(f"题号 {self.lineEdit_ID.text()} 的 {self.field} 字段") + sql = "SELECT genre FROM problems WHERE ID = (%s);" + val = (self.lineEdit_ID.text().zfill(6),) + self.cursor.execute(sql,val) + ret = self.cursor.fetchall() + if ret[0][0] is None: + self.originalcontent = "" + else: + self.originalcontent = ret[0][0].strip() + self.plainTextEdit_toedit.setPlainText(self.originalcontent) + def showans(self): + self.field = "答案" + self.label_2.setText(f"题号 {self.lineEdit_ID.text()} 的 {self.field} 字段") + sql = "SELECT ans FROM problems WHERE ID = (%s);" + val = (self.lineEdit_ID.text().zfill(6),) + self.cursor.execute(sql,val) + ret = self.cursor.fetchall() + if ret[0][0] is None: + self.originalcontent = "" + else: + self.originalcontent = ret[0][0].strip() + self.plainTextEdit_toedit.setPlainText(self.originalcontent) + def showsolution(self): + self.field = "解答" + self.label_2.setText(f"题号 {self.lineEdit_ID.text()} 的 {self.field} 字段") + sql = "SELECT solution FROM problems WHERE ID = (%s);" + val = (self.lineEdit_ID.text().zfill(6),) + self.cursor.execute(sql,val) + ret = self.cursor.fetchall() + if ret[0][0] is None: + self.originalcontent = "" + else: + self.originalcontent = ret[0][0].strip() + self.plainTextEdit_toedit.setPlainText(self.originalcontent) + def showorigin(self): + self.field = "来源" + self.label_2.setText(f"题号 {self.lineEdit_ID.text()} 的 {self.field} 字段") + sql = "SELECT origin FROM problems WHERE ID = (%s);" + val = (self.lineEdit_ID.text().zfill(6),) + self.cursor.execute(sql,val) + ret = self.cursor.fetchall() + if ret[0][0] is None: + self.originalcontent = "" + else: + self.originalcontent = ret[0][0].strip() + self.plainTextEdit_toedit.setPlainText(self.originalcontent) + def showremarks(self): + self.field = "备注" + self.label_2.setText(f"题号 {self.lineEdit_ID.text()} 的 {self.field} 字段") + sql = "SELECT date,remark_content FROM remarks WHERE ID = (%s);" + val = (self.lineEdit_ID.text().zfill(6),) + self.cursor.execute(sql,val) + ret_list = self.cursor.fetchall() + if len(ret_list) == 0: + self.originalcontent = "" + else: + self.originalcontent = "\n\n----------\n\n".join([ret[0]+"\t"+ret[1] for ret in ret_list]) + self.plainTextEdit_toedit.setPlainText(self.originalcontent) + def exec(self): + self.currentcontent = self.plainTextEdit_toedit.toPlainText().strip() + if self.currentcontent == self.originalcontent: + print("未改变, 不作处理.") + elif self.field in ["题目内容","答案","解答","来源"]: + corresp = {"题目内容":"content","答案":"ans","解答":"solution","来源":"origin"} + sql = f"UPDATE problems SET {corresp[self.field]} = %s WHERE ID = %s;" + val = (self.currentcontent,self.ID) + self.cursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,id,db_content) VALUE (%s,%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),f"修改{self.field}",self.ID,f"{self.originalcontent} -> {self.currentcontent}") + self.cursor.execute(sql,val) + if self.field == "题目内容": + sql = f"INSERT INTO edit_history (ID,date,editor) VALUE (%s,%s,%s);" + val = (self.ID,GetDate(),get_git_username()) + self.cursor.execute(sql,val) + print(f"{self.ID} {self.field} 修改已完成") + self.changedids.append(self.ID) + elif self.field == "类型": + sql = "UPDATE problems SET genre = %s WHERE ID = %s;" + val = (self.currentcontent,self.ID) + if self.currentcontent == "解答题": + self.cursor.execute("UPDATE problems SET space = %s WHERE ID = %s;",("4em",self.ID)) + else: + self.cursor.execute("UPDATE problems SET space = %s WHERE ID = %s;",("",self.ID)) + self.cursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,id,db_content) VALUE (%s,%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),f"修改类型",self.ID,f"{self.originalcontent} -> {self.currentcontent}") + self.cursor.execute(sql,val) + print(f"{self.ID} {self.field} 修改已完成") + self.changedids.append(self.ID) + elif self.field == "备注": + self.original_list = [item.strip() for item in self.originalcontent.split("-"*10)] + self.current_list = [item.strip() for item in self.currentcontent.split("-"*10)] + if len(self.original_list) != len(self.current_list): + print("有问题, 需保持备注的数量一致") + else: + for i in range(len(self.original_list)): + if self.original_list[i] != self.current_list[i]: + rm_date_origin,rm_content_origin = parseRemark(self.original_list[i]) + rm_date_current,rm_content_current = parseRemark(self.current_list[i]) + sql = "UPDATE remarks SET date = %s, remark_content = %s WHERE ID = %s AND date = %s AND remark_content = %s;" + val = (rm_date_current,rm_content_current,self.ID,rm_date_origin,rm_content_origin) + self.cursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,id,db_content) VALUE (%s,%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),f"修改备注",self.ID,f"{self.original_list[i]} -> {self.current_list[i]}") + self.cursor.execute(sql,val) + print(f"{self.ID} {self.field} 修改已完成") + self.changedids.append(self.ID) + + + + + + + + def tocommit(self): + if len(self.changedids) > 0: + configjson = BuildFullScheme + latexbody = "\\begin{enumerate}\n\n" + for id in sorted(list(set(self.changedids))): + latexbody += generateLaTeXBodyContentfromMariaDB(self.cursor,id,configjson) + "\n\n" + latexbody += "\\end{enumerate}" + latex_raw = ReadTextFile("模板文件/讲义模板.txt") + if configjson["教师版"] == True: + latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学") + + if sys.platform != "win32": #非win系统用默认字体 + latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) + latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) + latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,("试编译",latexbody)) #替换标题和bodystring + outputdir = os.path.join(os.getcwd(),"临时文件") + outputfilepath = os.path.join(outputdir,"试编译.tex") + SaveTextFile(latex_data,outputfilepath) + if XeLaTeXCompile(outputdir,"试编译.tex",times=1): + print("修改后检验成功, 已导入数据库.") + self.db.commit() + else: + print("修改后检验失败, 已回滚.") + self.db.rollback() + self.changedids = [] + else: + print("未作修改.") + + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow() + windows.show() + app.exec() + diff --git a/工具v3/题目内容直接编辑.ui b/工具v3/题目内容直接编辑.ui new file mode 100644 index 00000000..d99d8c98 --- /dev/null +++ b/工具v3/题目内容直接编辑.ui @@ -0,0 +1,174 @@ + + + Form + + + + 0 + 0 + 641 + 245 + + + + 题库内容直接编辑 + + + + + 10 + 10 + 54 + 16 + + + + 题号 + + + + + + 10 + 30 + 71 + 20 + + + + + + + 10 + 60 + 75 + 24 + + + + 题目内容 + + + + + + 10 + 90 + 75 + 24 + + + + 类型 + + + + + + 10 + 120 + 75 + 24 + + + + 答案 + + + + + + 10 + 150 + 75 + 24 + + + + 解答 + + + + + + 10 + 180 + 75 + 24 + + + + 来源 + + + + + + 10 + 210 + 75 + 24 + + + + 备注列表 + + + + + + 90 + 10 + 191 + 16 + + + + 题号为 的 字段 + + + + + + 90 + 30 + 471 + 201 + + + + + + + 570 + 30 + 61 + 91 + + + + 修改 + + + + + + 570 + 130 + 61 + 101 + + + + + true + + + + 提交 + + + + + +