summaryrefslogtreecommitdiff
path: root/addons/survey/controllers/main.py
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2019-12-10 12:30:21 +0000
committerDavid Beguin <dbe@odoo.com>2020-01-17 16:04:17 +0000
commitaedeccbeeaafe87ec0f80228a05b45dbc7140f72 (patch)
tree08cbc6b22e04a1165928d3f7a8d3cb3731616ec6 /addons/survey/controllers/main.py
parent860768b79bd710e97d51fc2ee992eeb41a6dcf96 (diff)
[IMP] survey : redesign frontend layout
In this commit, all the questions type have been redesigned to look more fancy. (impacted question types : radio and checkboxes, text boxes (textarea and text inputs, date and datetime inputs and matrix) For radio and checkboxes, both design have been aligned to work the same way (except checkboxes can still have more than one selected option). Selection by key have been applied on those two question types if the number of option is under 26 (to use all the alphabeat character for selection). This selection by key is only available on page per question layout. Tests have been adapted accordingly to the redesign (typically for choice and matrix inputs) * Progress Bar This commit adds a progress bar to the survey to inform the user where he is in the survey filling process. There are two progress modes: - Number : will display the number of the current page on the total number of pages (or questions if layout mode is question_per_page) - Percentage : will display the percentage of page or question already done So this leads to, on last page: - in Number mode : the progress bar div is 100% filled 3 / 3 pages [===] - in percentage mode : the progress bar is aligned to percentage 66% completed [== ] * Print Widget A widget is added for survey print mode in order to resize all textarea to fit their content, instead of showing a scroll bar. This can be usefull if user wants to print the results. He will get the entire content of the 'textarea answers' instead of only the two first lines. * Misc This commit also : - adds background image to survey. - redo quizz correction and add some data to illustrate non scored questions rendering in print template - review breadcrumb style Note : readonly data option on survey form widget is not set anywhere yet but the usage is done in prevention of the future work on presenter view for survey session mode. Task ID: '2150291' PR #43237
Diffstat (limited to 'addons/survey/controllers/main.py')
-rw-r--r--addons/survey/controllers/main.py53
1 files changed, 37 insertions, 16 deletions
diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py
index 94ced8b83f8..7b9491d3ed2 100644
--- a/addons/survey/controllers/main.py
+++ b/addons/survey/controllers/main.py
@@ -15,6 +15,8 @@ from odoo.http import request, content_disposition
from odoo.osv import expression
from odoo.tools import format_datetime, format_date
+from odoo.addons.web.controllers.main import Binary
+
_logger = logging.getLogger(__name__)
@@ -283,6 +285,24 @@ class Survey(http.Controller):
return request.render('survey.survey_page_fill',
self._prepare_survey_data(access_data['survey_sudo'], access_data['answer_sudo'], **post))
+ @http.route('/survey/get_background_image/<string:survey_token>/<string:answer_token>', type='http', auth="public", website=True, sitemap=False)
+ def survey_get_background(self, survey_token, answer_token):
+ access_data = self._get_access_data(survey_token, answer_token, ensure_token=True)
+ if access_data['validity_code'] is not True:
+ return werkzeug.exceptions.Forbidden()
+
+ survey_sudo, answer_sudo = access_data['survey_sudo'], access_data['answer_sudo']
+
+ status, headers, image_base64 = request.env['ir.http'].sudo().binary_content(
+ model='survey.survey', id=survey_sudo.id, field='background_image',
+ default_mimetype='image/png')
+
+ return Binary._content_image_get_response(status, headers, image_base64)
+
+ # ----------------------------------------------------------------
+ # JSON ROUTES to begin / continue survey (ajax navigation) + Tools
+ # ----------------------------------------------------------------
+
@http.route('/survey/begin/<string:survey_token>/<string:answer_token>', type='json', auth='public', website=True)
def survey_begin(self, survey_token, answer_token, **post):
""" Route used to start the survey user input and display the first survey page. """
@@ -427,6 +447,7 @@ class Survey(http.Controller):
'review': review,
'survey': survey_sudo,
'answer': answer_sudo,
+ 'scoring_display_correction': survey_sudo.scoring_type == 'scoring_with_answers' and answer_sudo,
'format_datetime': lambda dt: format_datetime(request.env, dt, dt_format=False),
'format_date': lambda date: format_date(request.env, date)
})
@@ -464,23 +485,8 @@ class Survey(http.Controller):
return self._generate_report(succeeded_attempt, download=True)
- def _generate_report(self, user_input, download=True):
- report = request.env.ref('survey.certification_report').sudo().render_qweb_pdf([user_input.id], data={'report_type': 'pdf'})[0]
-
- report_content_disposition = content_disposition('Certification.pdf')
- if not download:
- content_split = report_content_disposition.split(';')
- content_split[0] = 'inline'
- report_content_disposition = ';'.join(content_split)
-
- return request.make_response(report, headers=[
- ('Content-Type', 'application/pdf'),
- ('Content-Length', len(report)),
- ('Content-Disposition', report_content_disposition),
- ])
-
# ------------------------------------------------------------
- # REPORTING SURVEY ROUTES
+ # REPORTING SURVEY ROUTES AND TOOLS
# ------------------------------------------------------------
@http.route('/survey/results/<model("survey.survey"):survey>', type='http', auth='user', website=True)
@@ -509,6 +515,21 @@ class Survey(http.Controller):
'search_finished': post.get('finished') == 'true',
})
+ def _generate_report(self, user_input, download=True):
+ report = request.env.ref('survey.certification_report').sudo().render_qweb_pdf([user_input.id], data={'report_type': 'pdf'})[0]
+
+ report_content_disposition = content_disposition('Certification.pdf')
+ if not download:
+ content_split = report_content_disposition.split(';')
+ content_split[0] = 'inline'
+ report_content_disposition = ';'.join(content_split)
+
+ return request.make_response(report, headers=[
+ ('Content-Type', 'application/pdf'),
+ ('Content-Length', len(report)),
+ ('Content-Disposition', report_content_disposition),
+ ])
+
def _extract_filters_data(self, survey, post):
search_filters = []
line_filter_domain, line_choices = [], []