完善教育 #43

Merged
Ghost merged 1 commits from zhou into master 2026-09-17 18:02:39 +08:00
+9 -1
View File
@@ -31,7 +31,8 @@ class ExamQuestion(models.Model):
_rec_name = 'question_text_short'
sequence = fields.Integer(string='排序', default=10)
name = fields.Char(string='题目标题', help='内部管理用,不展示给学生', required=True)
name = fields.Char(string='题目标题', compute='_compute_name', store=True,
help='自动取题干文本(与题干一致),内部管理用,不展示给学生')
question_text = fields.Html(string='题干', sanitize=True, required=True)
question_text_short = fields.Char(
string='题干摘要', compute='_compute_question_text_short', store=True)
@@ -83,6 +84,13 @@ class ExamQuestion(models.Model):
text = re.sub(r'\s+', ' ', text).strip()
q.question_text_short = (text[:40] + '…') if len(text) > 40 else text
@api.depends('question_text')
def _compute_name(self):
import re
for q in self:
text = re.sub(r'<[^>]+>', ' ', q.question_text or '')
q.name = re.sub(r'\s+', ' ', text).strip()
@api.model
def default_get(self, fields_list):
"""新建题目时,单选/多选题默认带 A/B/C/D 四个选项行。"""