题目内容直接编辑功能 在工具v3 完成

This commit is contained in:
weiye.wang 2024-04-16 22:42:11 +08:00
parent 7bdf2b1ae3
commit 45a342cfe2
5 changed files with 464 additions and 1 deletions

View File

@ -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

View File

@ -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__":

View File

@ -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("统考数据导入",[]))#已完成

View File

@ -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()

View File

@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>245</height>
</rect>
</property>
<property name="windowTitle">
<string>题库内容直接编辑</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>54</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>题号</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_ID">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>71</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_content">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>题目内容</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_genre">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>类型</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_ans">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>答案</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_solution">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>解答</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_origin">
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>来源</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_remarks">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>备注列表</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>90</x>
<y>10</y>
<width>191</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>题号为 的 字段</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit_toedit">
<property name="geometry">
<rect>
<x>90</x>
<y>30</y>
<width>471</width>
<height>201</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>570</x>
<y>30</y>
<width>61</width>
<height>91</height>
</rect>
</property>
<property name="text">
<string>修改</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_tocommit">
<property name="geometry">
<rect>
<x>570</x>
<y>130</y>
<width>61</width>
<height>101</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>提交</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>