From 5602975376840cc5d80f993a37ba055118bc25c2 Mon Sep 17 00:00:00 2001 From: qitangbo Date: Thu, 17 Sep 2026 16:06:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- college/models/exam.py | 26 +++++++++++++++++++++----- college/views/menus.xml | 26 ++++++++++++++++++-------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/college/models/exam.py b/college/models/exam.py index 3d5a937..8c6241e 100644 --- a/college/models/exam.py +++ b/college/models/exam.py @@ -31,13 +31,13 @@ class ExamQuestion(models.Model): _rec_name = 'question_text_short' sequence = fields.Integer(string='排序', default=10) - name = fields.Char(string='题目标题', help='内部管理用,不展示给学生') + name = fields.Char(string='题目标题', help='内部管理用,不展示给学生', required=True) question_text = fields.Html(string='题干', sanitize=True, required=True) question_text_short = fields.Char( string='题干摘要', compute='_compute_question_text_short', store=True) question_type = fields.Selection( - _QUESTION_TYPES, string='题型', required=True, default='single_choice', index=True) + _QUESTION_TYPES, string='题型', default='single_choice', index=True) difficulty = fields.Selection( _DIFFICULTY_LEVELS, string='难度', default='medium') @@ -50,7 +50,7 @@ class ExamQuestion(models.Model): 'res.users', string='出题人', default=lambda self: self.env.user, required=True) visibility = fields.Selection( [('public', '公开'), ('private', '私有')], - string='可见范围', default='private', required=True, index=True, + string='可见范围', default='private', index=True, help='公开:同校其他老师均可查看并在组卷时选用;' '私有:仅出题人本人可见,其他老师看不到也无法选用。') @@ -66,7 +66,7 @@ class ExamQuestion(models.Model): string='答案说明', sanitize=True, help='答案解析:学生交卷后可查看本题解析。') - score = fields.Float(string='默认分值', default=1.0, required=True) + score = fields.Float(string='默认分值', default=1.0,) active = fields.Boolean(string='启用', default=True) @api.depends('question_text') @@ -77,11 +77,27 @@ class ExamQuestion(models.Model): text = re.sub(r'\s+', ' ', text).strip() q.question_text_short = (text[:40] + '…') if len(text) > 40 else text + @api.model + def default_get(self, fields_list): + """新建题目时,单选/多选题默认带 A/B/C/D 四个选项行。""" + res = super().default_get(fields_list) + if 'option_ids' in fields_list and res.get('question_type') in ( + 'single_choice', 'multiple_choice'): + res['option_ids'] = self._default_option_lines() + return res + + @staticmethod + def _default_option_lines(): + return [(0, 0, {'label': lbl, 'sequence': seq}) + for lbl, seq in (('A', 10), ('B', 20), ('C', 30), ('D', 40))] + @api.onchange('question_type') def _onchange_question_type(self): - """切换题型时,对判断题给出默认正确答案提示。""" + """切换题型时:判断题给默认正确答案;单选/多选在无选项时补 A/B/C/D。""" if self.question_type == 'true_false': self.correct_answer = 'True' + if self.question_type in ('single_choice', 'multiple_choice') and not self.option_ids: + self.option_ids = self._default_option_lines() def _get_correct_options(self): """返回本题的正确选项记录(仅选择题有效)。""" diff --git a/college/views/menus.xml b/college/views/menus.xml index bef73ee..25016ae 100644 --- a/college/views/menus.xml +++ b/college/views/menus.xml @@ -12,17 +12,21 @@ - + + @@ -158,6 +162,12 @@ else: + + @@ -361,13 +371,13 @@ else: sequence="20"/> @@ -383,8 +393,8 @@ else: -- 2.34.1