Purpose of this commit is to introduce a new way of displaying and managing slides in eLearning module. Its purpose is to give a better experience to users when going through a course. Notably a fullscreen mode allows to take lessons one by one without going out of the elearning display. Integration of all slide types eases taking the course step by step. Quiz are introduced in this commit. Those are an addition to slides with some question / answers (multiple choice). It allows customer to gain karma and improves gamification. Certifications are still done using the survey application. Quiz targets only small tests at the end of a given slide. A new widget is added to display and control slide display in fullscreen mode. Old display is still available for documentation channels or when going out of fullscreen mode, to see details on comments / review / statistics and have access to share options. This commit is linked to task ID 1902304 and PR #29876. It closes the main work on refactoring website slides into eLearning, with other tasks already merged in current community [1][2][3][4][5]. [1] Task ID 1940360 landed atb2149bc7a2: certification inclusion [2] Task ID1936153landed at6c6179e57c: homepage inclusion [3] Task ID 1937160 landed at8b7605c9e5: selling courses [4] Task ID 1922159 and 1940516 landed at5fa651cb01and6a64c3ce82: new user profile and gamification of slides / forum [5] Task ID 1938643 landed at77b5673a0d: upload channel/slide
52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class SlideQuestion(models.Model):
|
|
_name = "slide.question"
|
|
_rec_name = "question"
|
|
_description = """
|
|
Question for a slide. A slide can have multiple questions and each question
|
|
must have at least 2 possible answers and only one good answer.
|
|
"""
|
|
|
|
sequence = fields.Integer("Sequence", default=10)
|
|
question = fields.Char("Question Name", required=True)
|
|
slide_id = fields.Many2one('slide.slide', string="Slide")
|
|
answer_ids = fields.One2many('slide.answer', 'question_id', string="Answer")
|
|
|
|
@api.constrains('answer_ids')
|
|
def _check_only_one_good_answer(self):
|
|
for question in self:
|
|
good_answer_count = 0
|
|
for answer in question.answer_ids:
|
|
if answer.is_correct:
|
|
good_answer_count += 1
|
|
if good_answer_count > 1:
|
|
raise ValidationError(_('A question can only have one good answer'))
|
|
|
|
@api.constrains('answer_ids')
|
|
def _check_correct_answer(self):
|
|
for question in self:
|
|
if not any([answer.is_correct for answer in question.answer_ids]):
|
|
raise ValidationError(_("A question must at least have one good answer"))
|
|
|
|
@api.constrains('answer_ids')
|
|
def _check_at_least_2_answers(self):
|
|
for question in self:
|
|
if len(question.answer_ids) < 2:
|
|
raise ValidationError(_("A question must at least have two possible answers"))
|
|
|
|
|
|
class SlideAnswer(models.Model):
|
|
_name = "slide.answer"
|
|
_rec_name = "text_value"
|
|
_description = """Answer for a slide question"""
|
|
|
|
question_id = fields.Many2one('slide.question', string="Question")
|
|
text_value = fields.Char("Answer", required=True,)
|
|
is_correct = fields.Boolean("Is correct answer", default=False)
|