diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-11-28 10:47:08 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-11-29 13:36:25 +0000 |
| commit | a4abdfa3164ab6cc5a77bc17a42619be49960f2c (patch) | |
| tree | 3a599275ebbad66db5c5e9f9bdde045058cb0a73 /addons/website_slides/models/slide_question.py | |
| parent | 0b5f1fbead827363f70deb8359805af94cb3eb94 (diff) | |
[IMP] website_slides: merge slide quiz answers constraints in a single method
Currently there are several checks on answer integrity for slide quiz
questions. In this commit we simplify code to effectively implement
what is requested: 1 valid answer and at least 1 invalid answer.
Task ID 1999636
PR #35326
Diffstat (limited to 'addons/website_slides/models/slide_question.py')
| -rw-r--r-- | addons/website_slides/models/slide_question.py | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/addons/website_slides/models/slide_question.py b/addons/website_slides/models/slide_question.py index 62daeccf534..8258b26e71a 100644 --- a/addons/website_slides/models/slide_question.py +++ b/addons/website_slides/models/slide_question.py @@ -20,26 +20,12 @@ class SlideQuestion(models.Model): done_count = fields.Integer(compute="_compute_statistics", groups='website.group_website_publisher') @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(_('Question "%s" can only have one good answer') % question.question) - - @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(_('Question "%s" must at least have one good answer') % question.question) - - @api.constrains('answer_ids') - def _check_at_least_2_answers(self): + def _check_answers_integrity(self): for question in self: + if len(question.answer_ids.filtered(lambda answer: answer.is_correct)) != 1: + raise ValidationError(_('Question "%s" must have 1 correct answer') % question.question) if len(question.answer_ids) < 2: - raise ValidationError(_('Question "%s" has no valid answer, please set one') % question.question) + raise ValidationError(_('Question "%s" must have 1 correct answer and at least 1 invalid answer') % question.question) @api.depends('slide_id') def _compute_statistics(self): |
