优化菜单和默认值 #40
+21
-5
@@ -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):
|
||||
"""返回本题的正确选项记录(仅选择题有效)。"""
|
||||
|
||||
+18
-8
@@ -12,17 +12,21 @@
|
||||
<menuitem id="menu_yuthon_product_intro"
|
||||
name="产品介绍"
|
||||
web_icon="college,static/src/img/product_intro.png"
|
||||
sequence="0"
|
||||
sequence="-10"
|
||||
action="action_yuthon_product_intro"
|
||||
groups="college.group_teacher,college.group_student,base.group_system"/>
|
||||
|
||||
<!-- ===================== 我的实训(顶级菜单,置顶) ===================== -->
|
||||
<!-- ===================== 我的实训(顶级菜单,置顶;作为实训相关功能的容器) ===================== -->
|
||||
<menuitem id="menu_yuthon_training"
|
||||
name="我的实训"
|
||||
web_icon="college,static/src/img/training.png"
|
||||
sequence="1"
|
||||
action="action_yuthon_school_training"
|
||||
groups="college.group_teacher,college.group_student,base.group_system"/>
|
||||
<menuitem id="menu_yuthon_training_overview"
|
||||
name="实训概览"
|
||||
parent="menu_yuthon_training"
|
||||
action="action_yuthon_school_training"
|
||||
sequence="10"/>
|
||||
|
||||
<!-- ===================== 我的课程(统一入口,按用户角色路由) ===================== -->
|
||||
<!-- 老师 / 管理员 → action_yuthon_school_course_my(老师端我的课程) -->
|
||||
@@ -158,6 +162,12 @@ else:
|
||||
<menuitem id="menu_yuthon_course_root"
|
||||
name="课程管理"
|
||||
web_icon="college,static/src/img/Course Management.png"
|
||||
sequence="10"
|
||||
groups="college.group_teacher,base.group_system"/>
|
||||
<!-- 全部课程(原来直连的 action 移到这里) -->
|
||||
<menuitem id="menu_yuthon_course_all"
|
||||
name="全部课程"
|
||||
parent="menu_yuthon_course_root"
|
||||
action="action_yuthon_school_course_all"
|
||||
sequence="10"
|
||||
groups="college.group_teacher,base.group_system"/>
|
||||
@@ -361,13 +371,13 @@ else:
|
||||
sequence="20"/>
|
||||
<menuitem id="menu_yuthon_import_wizard"
|
||||
name="导入师生"
|
||||
parent="menu_yuthon_about"
|
||||
parent="menu_yuthon_org_staff"
|
||||
action="action_yuthon_school_import_wizard"
|
||||
sequence="30"
|
||||
sequence="40"
|
||||
groups="college.group_teacher,base.group_system"/>
|
||||
<menuitem id="menu_yuthon_course_import_wizard"
|
||||
name="课程导入"
|
||||
parent="menu_yuthon_about"
|
||||
parent="menu_yuthon_course_root"
|
||||
action="action_yuthon_school_course_import_wizard"
|
||||
sequence="40"
|
||||
groups="college.group_teacher,base.group_system"/>
|
||||
@@ -383,8 +393,8 @@ else:
|
||||
</record>
|
||||
<menuitem id="menu_yuthon_about_question_import"
|
||||
name="题库导入"
|
||||
parent="menu_yuthon_about"
|
||||
parent="menu_yuthon_exam_root"
|
||||
action="action_yuthon_about_question_import"
|
||||
sequence="50"
|
||||
sequence="60"
|
||||
groups="college.group_teacher,base.group_system"/>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user