[IMP] survey: illustrate your questions and answers with media

- Purpose:

Allow the addition of media on a question and/or answers in order to describe
or illustrate them.

- Specifications:

During the creation of a question, you have now the possibility to set a
description of a question by filling an html field under the tab "Description".
This field can be used to enter text or to illustrate the question with an
image or video.

There is also an option to add pictures on answers for simple and multiple
choice questions. Those are displayed as clickable images.

Task ID 2083823
PR #42228
This commit is contained in:
Jérémy Hennecart
2020-01-29 10:09:03 +00:00
committed by Thibault Delavallée
parent 35b84646ff
commit 372d2eb09c
3 changed files with 20 additions and 1 deletions
+5 -1
View File
@@ -54,7 +54,9 @@ class SurveyQuestion(models.Model):
# question generic data
title = fields.Char('Title', required=True, translate=True)
description = fields.Html('Description', help="Use this field to add additional explanations about your question", translate=True)
description = fields.Html(
'Description', translate=True, sanitize=False, # TDE TODO: sanitize but find a way to keep youtube iframe media stuff
help="Use this field to add additional explanations about your question or to illustrate it with pictures or a video")
survey_id = fields.Many2one('survey.survey', string='Survey', ondelete='cascade')
scoring_type = fields.Selection(related='survey_id.scoring_type', string='Scoring Type', readonly=True)
sequence = fields.Integer('Sequence', default=10)
@@ -86,6 +88,7 @@ class SurveyQuestion(models.Model):
suggested_answer_ids = fields.One2many(
'survey.question.answer', 'question_id', string='Types of answers', copy=True,
help='Labels used for proposed choices: simple choice, multiple choice and columns of matrix')
allow_value_image = fields.Boolean('Images on answers', help='Display images in addition to answer label. Valid only for simple / multiple choice questions.')
# -- matrix
matrix_subtype = fields.Selection([
('simple', 'One choice per row'),
@@ -447,6 +450,7 @@ class SurveyQuestionAnswer(models.Model):
matrix_question_id = fields.Many2one('survey.question', string='Question (as matrix row)', ondelete='cascade')
sequence = fields.Integer('Label Sequence order', default=10)
value = fields.Char('Suggested value', translate=True, required=True)
value_image = fields.Image('Image', max_width=256, max_height=256)
is_correct = fields.Boolean('Is a correct answer')
answer_score = fields.Float('Score for this choice', help="A positive score indicates a correct choice; a negative or null score indicates a wrong answer")
@@ -109,6 +109,8 @@
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="value" string="Choices"/>
<field name="value_image" options="{'accepted_file_extensions': 'image/*'}"
attrs="{'column_invisible': ['|', ('parent.allow_value_image', '=', False), ('parent.question_type', '=', 'matrix')]}"/>
<field name="is_correct" attrs="{'column_invisible': ['|', ('parent.scoring_type', '=', 'no_scoring'), ('parent.question_type', '=', 'matrix')]}"/>
<field name="answer_score" attrs="{'column_invisible': ['|', ('parent.scoring_type', '=', 'no_scoring'), ('parent.question_type', '=', 'matrix')]}"/>
</tree>
@@ -122,6 +124,9 @@
</tree>
</field>
</page>
<page string="Description" name="survey_description">
<field name="description" widget="html"/>
</page>
<page string="Options" name="options">
<group string="Constraints">
<group colspan="2" col="4">
@@ -150,6 +155,7 @@
</group>
<group string="Display" attrs="{'invisible':[('question_type','not in',['simple_choice', 'multiple_choice'])]}">
<field name="column_nb" string="Number of columns"/>
<field name="allow_value_image"/>
</group>
<group string="Allow Comments" attrs="{'invisible':[('question_type','not in',['simple_choice','multiple_choice', 'matrix'])]}">
<field name='comments_allowed' />
+9
View File
@@ -300,6 +300,13 @@
</div>
</template>
<template id="question_suggested_value_image" name="Image from the question suggested answer">
<div t-if="question.allow_value_image and label.value_image"
t-field="label.value_image"
class="d-flex my-3 justify-content-center"
t-options='{"widget": "image", "alt-field": "name", "itemprop": "image"}'/>
</template>
<template id="question_simple_choice" name="Question: simple choice">
<t t-set="answer_line" t-value="answer_lines.filtered(lambda line: line.suggested_answer_id)"/>
<t t-set="comment_line" t-value="answer_lines.filtered(lambda line: line.value_char_box)"/>
@@ -331,6 +338,7 @@
t-att-data-selection-key="letters[item_idx] if useKeySelection else ''"/>
<i class="fa fa-check-circle float-right mt-1 position-relative"></i>
<i class="fa fa-circle float-right mt-1 position-relative"></i>
<t t-call="survey.question_suggested_value_image"/>
</label>
</t>
</div>
@@ -392,6 +400,7 @@
<span class="ml-2" t-field='label.value'/>
<i class="fa fa-check-square float-right mt-1 position-relative"></i>
<i class="fa fa-square float-right mt-1 position-relative"></i>
<t t-call="survey.question_suggested_value_image"/>
</label>
</t>
</div>