保存当前dev_haoran代码修改
This commit is contained in:
parent
1baa361516
commit
2d8949202b
BIN
learning_center/models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
learning_center/models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -35,7 +35,11 @@ class CourseHomework(models.Model):
|
|||||||
teaching_class_id = fields.Many2one('course.teaching_class', string='教学班',
|
teaching_class_id = fields.Many2one('course.teaching_class', string='教学班',
|
||||||
ondelete='cascade', domain="[('course_id', '=', course_id)]")
|
ondelete='cascade', domain="[('course_id', '=', course_id)]")
|
||||||
submit_ids = fields.One2many('course.homework.submit', 'homework_id', string='提交记录')
|
submit_ids = fields.One2many('course.homework.submit', 'homework_id', string='提交记录')
|
||||||
|
<<<<<<< HEAD
|
||||||
score_item_ids = fields.One2many('course.score.item', 'homework_id', string='成绩项目')
|
score_item_ids = fields.One2many('course.score.item', 'homework_id', string='成绩项目')
|
||||||
|
=======
|
||||||
|
score_item_ids = fields.One2many('course.score.item', 'homework_id', string='成绩项')
|
||||||
|
>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb
|
||||||
|
|
||||||
# ====================== 新增:自动计算提交通道是否开启 ======================
|
# ====================== 新增:自动计算提交通道是否开启 ======================
|
||||||
@api.depends('state', 'deadline')
|
@api.depends('state', 'deadline')
|
||||||
@ -82,6 +86,7 @@ class CourseHomework(models.Model):
|
|||||||
self.publish_time = fields.Datetime.now()
|
self.publish_time = fields.Datetime.now()
|
||||||
# 1. 批量为本班学生生成空白未提交记录
|
# 1. 批量为本班学生生成空白未提交记录
|
||||||
self._auto_create_empty_submit()
|
self._auto_create_empty_submit()
|
||||||
|
<<<<<<< HEAD
|
||||||
# 新增:自动生成对应作业的学生成绩明细
|
# 新增:自动生成对应作业的学生成绩明细
|
||||||
self._auto_create_homework_score_detail()
|
self._auto_create_homework_score_detail()
|
||||||
# 2. 推送作业通知给学生
|
# 2. 推送作业通知给学生
|
||||||
@ -137,6 +142,39 @@ class CourseHomework(models.Model):
|
|||||||
|
|
||||||
if detail_vals_list:
|
if detail_vals_list:
|
||||||
self.env['course.student.score.detail'].create(detail_vals_list)
|
self.env['course.student.score.detail'].create(detail_vals_list)
|
||||||
|
=======
|
||||||
|
# 2. 推送作业通知给学生
|
||||||
|
self._send_homework_notice_to_students()
|
||||||
|
|
||||||
|
def _send_homework_notice_to_students(self):
|
||||||
|
"""发布作业后推送消息给教学班学生"""
|
||||||
|
self.ensure_one()
|
||||||
|
if not self.teaching_class_id:
|
||||||
|
return
|
||||||
|
# 获取当前教学班所有已选课学生
|
||||||
|
enrolls = self.env['course.teaching_class.enrollment'].search([
|
||||||
|
('teaching_class_id', '=', self.teaching_class_id.id),
|
||||||
|
('state', '=', 'enrolled')
|
||||||
|
])
|
||||||
|
student_users = enrolls.mapped('student_id.user_id').filtered(lambda u: u)
|
||||||
|
if not student_users:
|
||||||
|
return
|
||||||
|
# 消息内容
|
||||||
|
subject = f"新作业发布:{self.name}"
|
||||||
|
body = f"""
|
||||||
|
<p>课程:{self.course_id.name}</p>
|
||||||
|
<p>作业名称:{self.name}</p>
|
||||||
|
<p>截止时间:{self.deadline or '无'}</p>
|
||||||
|
<p>作业要求:{self.requirement or '无'}</p>
|
||||||
|
"""
|
||||||
|
# 发送消息(关联当前作业记录,学生在消息中心可直接跳转)
|
||||||
|
self.message_post(
|
||||||
|
subject=subject,
|
||||||
|
body=body,
|
||||||
|
partner_ids=student_users.mapped('partner_id').ids,
|
||||||
|
subtype_xmlid='mail.mt_comment'
|
||||||
|
)
|
||||||
|
>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb
|
||||||
|
|
||||||
def _auto_create_empty_submit(self):
|
def _auto_create_empty_submit(self):
|
||||||
"""仅发布时执行:自动给教学班所有已选课学生生成空白未提交记录"""
|
"""仅发布时执行:自动给教学班所有已选课学生生成空白未提交记录"""
|
||||||
@ -164,12 +202,16 @@ class CourseHomework(models.Model):
|
|||||||
batch_vals.append({
|
batch_vals.append({
|
||||||
'homework_id': self.id,
|
'homework_id': self.id,
|
||||||
'student_id': stu_id,
|
'student_id': stu_id,
|
||||||
|
<<<<<<< HEAD
|
||||||
'course_score_item_id':self.course_score_item_id.id,
|
'course_score_item_id':self.course_score_item_id.id,
|
||||||
|
=======
|
||||||
|
>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb
|
||||||
'state': 'unsubmit' # 默认未提交
|
'state': 'unsubmit' # 默认未提交
|
||||||
})
|
})
|
||||||
# 批量创建空白提交记录
|
# 批量创建空白提交记录
|
||||||
submit_model.create(batch_vals)
|
submit_model.create(batch_vals)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
def _send_homework_notice_to_students(self):
|
def _send_homework_notice_to_students(self):
|
||||||
"""发布作业后推送消息给教学班学生"""
|
"""发布作业后推送消息给教学班学生"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@ -199,6 +241,8 @@ class CourseHomework(models.Model):
|
|||||||
subtype_xmlid='mail.mt_note'
|
subtype_xmlid='mail.mt_note'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb
|
||||||
# ====================== 草稿/关闭作业 ======================
|
# ====================== 草稿/关闭作业 ======================
|
||||||
def action_draft(self):
|
def action_draft(self):
|
||||||
self.state = 'draft'
|
self.state = 'draft'
|
||||||
@ -325,6 +369,7 @@ class CourseHomework(models.Model):
|
|||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
homework_record = super().create(vals)
|
homework_record = super().create(vals)
|
||||||
# 草稿状态不执行自动生成提交记录,移到action_publish
|
# 草稿状态不执行自动生成提交记录,移到action_publish
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
target_a = self.env["course.score.item"].search([
|
target_a = self.env["course.score.item"].search([
|
||||||
("name", "=", "作业"),
|
("name", "=", "作业"),
|
||||||
@ -336,4 +381,6 @@ class CourseHomework(models.Model):
|
|||||||
target_a.write({
|
target_a.write({
|
||||||
"homework_ids": [(4, homework_record.id)]
|
"homework_ids": [(4, homework_record.id)]
|
||||||
})
|
})
|
||||||
|
=======
|
||||||
|
>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb
|
||||||
return homework_record
|
return homework_record
|
||||||
@ -93,7 +93,10 @@ class CourseHomeworkSubmit(models.Model):
|
|||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
submit_rec = super().create(vals)
|
submit_rec = super().create(vals)
|
||||||
self._check_submit_change_state(submit_rec)
|
self._check_submit_change_state(submit_rec)
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb
|
||||||
return submit_rec
|
return submit_rec
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user