完善教育 #42
@@ -59,6 +59,12 @@ class ExamQuestion(models.Model):
|
||||
correct_answer = fields.Char(
|
||||
string='正确答案',
|
||||
help='判断题填 True/False;填空题填标准答案(多个空用 | 分隔)。选择题由「选项」的「正确答案」标记决定。')
|
||||
# 判断题专用:把 True/False 映射成 对/错 展示与选择,存储仍是 True/False
|
||||
correct_answer_tf = fields.Selection(
|
||||
[('True', '对'), ('False', '错')],
|
||||
string='正确答案',
|
||||
compute='_compute_correct_answer_tf', inverse='_inverse_correct_answer_tf',
|
||||
help='判断题的正确答案:对 / 错。')
|
||||
reference_answer = fields.Html(
|
||||
string='参考答案', sanitize=True,
|
||||
help='简答题的参考答案,供老师评阅与学生查看解析时参考。')
|
||||
@@ -99,6 +105,16 @@ class ExamQuestion(models.Model):
|
||||
if self.question_type in ('single_choice', 'multiple_choice') and not self.option_ids:
|
||||
self.option_ids = self._default_option_lines()
|
||||
|
||||
@api.depends('correct_answer')
|
||||
def _compute_correct_answer_tf(self):
|
||||
for q in self:
|
||||
q.correct_answer_tf = q.correct_answer if q.correct_answer in ('True', 'False') else 'True'
|
||||
|
||||
def _inverse_correct_answer_tf(self):
|
||||
for q in self:
|
||||
if q.correct_answer_tf:
|
||||
q.correct_answer = q.correct_answer_tf
|
||||
|
||||
def _get_correct_options(self):
|
||||
"""返回本题的正确选项记录(仅选择题有效)。"""
|
||||
self.ensure_one()
|
||||
|
||||
@@ -61,9 +61,12 @@
|
||||
</page>
|
||||
<page string="答案与解析" name="answer">
|
||||
<group>
|
||||
<field name="correct_answer_tf"
|
||||
invisible="question_type != 'true_false'"
|
||||
required="question_type == 'true_false'"/>
|
||||
<field name="correct_answer"
|
||||
invisible="question_type not in ('true_false','fill_blank')"
|
||||
required="question_type in ('true_false','fill_blank')"/>
|
||||
invisible="question_type != 'fill_blank'"
|
||||
required="question_type == 'fill_blank'"/>
|
||||
<field name="reference_answer" widget="html"
|
||||
invisible="question_type != 'essay'"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user