From b70ccc45bd095022de64719796d9f80f5fdae427 Mon Sep 17 00:00:00 2001 From: mreficent Date: Tue, 25 Sep 2018 15:43:18 +0000 Subject: [PATCH] [REF] survey: rename survey.question type field to question_type Purpose of this commit is to rename type column to something matching the the real business use of the field. That way it is easier to find and grep in the code. It also lessens potential conflicts with type build-in python function. It also lessens conflicts when using the field in JS as type is a build-in attribute. Renaming type column is a long-living issue. We choose to do it at the beginning of the v13 development to catch errors as soon as possible. This commit is linked to task ID 1896245. It is also a subpart of community PR #27599. --- .../data/survey_survey_data.xml | 16 ++--- addons/survey/controllers/main.py | 10 +-- addons/survey/data/survey_demo_feedback.xml | 26 ++++---- addons/survey/models/survey.py | 20 +++--- addons/survey/tests/test_survey.py | 32 +++++----- addons/survey/views/survey_result.xml | 28 ++++----- addons/survey/views/survey_templates.xml | 28 ++++----- addons/survey/views/survey_views.xml | 62 +++++++++---------- 8 files changed, 111 insertions(+), 111 deletions(-) diff --git a/addons/hr_recruitment_survey/data/survey_survey_data.xml b/addons/hr_recruitment_survey/data/survey_survey_data.xml index d9228f4fb47..c12284cd20b 100644 --- a/addons/hr_recruitment_survey/data/survey_survey_data.xml +++ b/addons/hr_recruitment_survey/data/survey_survey_data.xml @@ -20,13 +20,13 @@ 1 From which university will you graduate? - textbox + textbox 2 What is your gender? - simple_choice + simple_choice dropdown @@ -43,7 +43,7 @@ 3 What age group do you belong to? - simple_choice + simple_choice columns 4 @@ -99,25 +99,25 @@ 1 Knowledge - free_text + free_text 2 Education - free_text + free_text 3 Experience - free_text + free_text 4 Activities - free_text + free_text @@ -130,7 +130,7 @@ 1 Rate the Importance - matrix + matrix simple diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 3674012e091..613d47824df 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -166,9 +166,9 @@ class Survey(http.Controller): answer_value = None if answer.answer_type == 'free_text': answer_value = answer.value_free_text - elif answer.answer_type == 'text' and answer.question_id.type == 'textbox': + elif answer.answer_type == 'text' and answer.question_id.question_type == 'textbox': answer_value = answer.value_text - elif answer.answer_type == 'text' and answer.question_id.type != 'textbox': + elif answer.answer_type == 'text' and answer.question_id.question_type != 'textbox': # here come comment answers for matrices, simple choice and multiple choice answer_tag = "%s_%s" % (answer_tag, 'comment') answer_value = answer.value_text @@ -363,13 +363,13 @@ class Survey(http.Controller): current_filters = current_filters if current_filters else [] Survey = request.env['survey.survey'] result = [] - if question.type == 'multiple_choice': + if question.question_type == 'multiple_choice': result.append({'key': ustr(question.question), 'values': Survey.prepare_result(question, current_filters)['answers'] }) - if question.type == 'simple_choice': + if question.question_type == 'simple_choice': result = Survey.prepare_result(question, current_filters)['answers'] - if question.type == 'matrix': + if question.question_type == 'matrix': data = Survey.prepare_result(question, current_filters) for answer in data['answers']: values = [] diff --git a/addons/survey/data/survey_demo_feedback.xml b/addons/survey/data/survey_demo_feedback.xml index 3d3285271a3..01e591dbddb 100644 --- a/addons/survey/data/survey_demo_feedback.xml +++ b/addons/survey/data/survey_demo_feedback.xml @@ -21,7 +21,7 @@ 1 Are you using Odoo on a daily basis? - simple_choice + simple_choice dropdown @@ -49,7 +49,7 @@ 2 Which modules are you using/testing? - multiple_choice + multiple_choice 4 @@ -95,7 +95,7 @@ what have been your difficulties.</p> 1 What do you think about the documentation available on doc.odoo.com? - matrix + matrix simple @@ -148,7 +148,7 @@ what have been your difficulties.</p> 2 What do you think about the process views of Odoo, available in the web client ? - matrix + matrix simple @@ -201,13 +201,13 @@ what have been your difficulties.</p> 3 Do you have suggestions on how to improve the process view ? - free_text + free_text 4 What do you think about the structure of the menus? - multiple_choice + multiple_choice 4 @@ -230,7 +230,7 @@ what have been your difficulties.</p> 5 What do you think about the groups of users? - matrix + matrix simple @@ -283,7 +283,7 @@ what have been your difficulties.</p> 6 What do you think about the structure of the menus? - simple_choice + simple_choice columns 4 @@ -307,7 +307,7 @@ what have been your difficulties.</p> 7 What do you think about configuration wizards? - matrix + matrix simple @@ -362,7 +362,7 @@ what have been your difficulties.</p> 1 How do you contribute or plan to contribute to Odoo? - multiple_choice + multiple_choice 6 @@ -395,13 +395,13 @@ what have been your difficulties.</p> 2 Do you have a proposition to help people to contribute? - free_text + free_text 3 Do you have a proposition to attract new contributors? - free_text + free_text @@ -414,7 +414,7 @@ what have been your difficulties.</p> 1 Where do you develop your new features? - multiple_choice + multiple_choice 6 diff --git a/addons/survey/models/survey.py b/addons/survey/models/survey.py index 95a1cc1fdd1..f6ae9f98c8c 100644 --- a/addons/survey/models/survey.py +++ b/addons/survey/models/survey.py @@ -226,7 +226,7 @@ class Survey(models.Model): result_summary = {} # Calculate and return statistics for choice - if question.type in ['simple_choice', 'multiple_choice']: + if question.question_type in ['simple_choice', 'multiple_choice']: comments = [] answers = OrderedDict((label.id, {'text': label.value, 'count': 0, 'answer_id': label.id}) for label in question.labels_ids) for input_line in question.user_input_line_ids: @@ -237,7 +237,7 @@ class Survey(models.Model): result_summary = {'answers': list(answers.values()), 'comments': comments} # Calculate and return statistics for matrix - if question.type == 'matrix': + if question.question_type == 'matrix': rows = OrderedDict() answers = OrderedDict() res = dict() @@ -254,14 +254,14 @@ class Survey(models.Model): result_summary = {'answers': answers, 'rows': rows, 'result': res, 'comments': comments} # Calculate and return statistics for free_text, textbox, date - if question.type in ['free_text', 'textbox', 'date']: + if question.question_type in ['free_text', 'textbox', 'date']: result_summary = [] for input_line in question.user_input_line_ids: if not(current_filters) or input_line.user_input_id.id in current_filters: result_summary.append(input_line) # Calculate and return statistics for numerical_box - if question.type == 'numerical_box': + if question.question_type == 'numerical_box': result_summary = {'input_lines': []} all_inputs = [] for input_line in question.user_input_line_ids: @@ -434,14 +434,14 @@ class SurveyQuestion(models.Model): oldname='descriptive_text') # Answer - type = fields.Selection([ + question_type = fields.Selection([ ('free_text', 'Multiple Lines Text Box'), ('textbox', 'Single Line Text Box'), ('numerical_box', 'Numerical Value'), ('date', 'Date'), ('simple_choice', 'Multiple choice: only one answer'), ('multiple_choice', 'Multiple choice: multiple answers allowed'), - ('matrix', 'Matrix')], string='Type of Question', default='free_text', required=True) + ('matrix', 'Matrix')], string='Type of Question', default='free_text', required=True, oldname='type') matrix_subtype = fields.Selection([('simple', 'One choice per row'), ('multiple', 'Multiple choices per row')], string='Matrix Type', default='simple') labels_ids = fields.One2many('survey.label', 'question_id', string='Types of answers', oldname='answer_choice_ids', copy=True) @@ -509,9 +509,9 @@ class SurveyQuestion(models.Model): """ Validate question, depending on question type and parameters """ self.ensure_one() try: - checker = getattr(self, 'validate_' + self.type) + checker = getattr(self, 'validate_' + self.question_type) except AttributeError: - _logger.warning(self.type + ": This type of question has no validation method") + _logger.warning(self.question_type + ": This type of question has no validation method") return {} else: return checker(post, answer_tag) @@ -846,9 +846,9 @@ class SurveyUserInputLine(models.Model): overwritten (in order to maintain data consistency). """ try: - saver = getattr(self, 'save_line_' + question.type) + saver = getattr(self, 'save_line_' + question.question_type) except AttributeError: - _logger.error(question.type + ": This type of question has no saving function") + _logger.error(question.question_type + ": This type of question has no saving function") return False else: saver(user_input_id, question, post, answer_tag) diff --git a/addons/survey/tests/test_survey.py b/addons/survey/tests/test_survey.py index 03c5bbbc5f4..2b6d46b14ff 100644 --- a/addons/survey/tests/test_survey.py +++ b/addons/survey/tests/test_survey.py @@ -43,8 +43,8 @@ class TestSurvey(TransactionCase): self.assertEqual(question.question, "Q0", msg="Title of the Question is somehow modified.") def test_01_question_type_validation_save_line_function(self): - for (question_type, text) in self.env['survey.question']._fields['type'].selection: - # Each question ype must have validation function. + for (question_type, text) in self.env['survey.question']._fields['question_type'].selection: + # Each question type must have validation function. self.assertTrue(hasattr(self.env['survey.question'], 'validate_' + question_type), msg="Question must have a validation method in\ the form of 'validate_' followed by the name of the type.") @@ -53,24 +53,24 @@ class TestSurvey(TransactionCase): the form of 'save_line_' followed by the name of the type.") def test_02_question_answer_required(self): - for (question_type, text) in self.env['survey.question']._fields['type'].selection: + for (question_type, text) in self.env['survey.question']._fields['question_type'].selection: # Blank value of field is not accepted for mandatory questions. if question_type == 'multiple_choice': question = self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': 'multiple_choice', + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'multiple_choice', 'constr_mandatory': True, 'constr_error_msg': 'Error', 'labels_ids': [(0, 0, {'value': "MChoice0", "quizz_mark": 0}), (0, 0, {'value': "MChoice1", "quizz_mark": 0})]}) elif question_type == 'matrix': question = self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': 'matrix', 'matrix_subtype': 'simple', + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'matrix', 'matrix_subtype': 'simple', 'constr_mandatory': True, 'constr_error_msg': 'Error', 'labels_ids': [(0, 0, {'value': "Column0", "quizz_mark": 0}), (0, 0, {'value': "Column1", "quizz_mark": 0})], 'labels_ids_2': [(0, 0, {'value': "Row0", "quizz_mark": 0}), (0, 0, {'value': "Row1", "quizz_mark": 0})]}) else: question = self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': question_type, 'constr_mandatory': True, 'constr_error_msg': 'Error'}) + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': question_type, 'constr_mandatory': True, 'constr_error_msg': 'Error'}) answer_tag = '%s_%s_%s' % (self.survey1.id, self.page1.id, question.id) self.assertDictEqual({answer_tag: "Error"}, question.validate_question({answer_tag: ''}, answer_tag), msg=("Validation function for type %s is unable to generate error if it is mandatory and answer is blank." % question_type)) @@ -78,9 +78,9 @@ class TestSurvey(TransactionCase): def test_03_question_textbox(self): questions = [ self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': 'textbox', 'validation_email': True}), + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'textbox', 'validation_email': True}), self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q1', 'type': 'textbox', 'validation_required': True, + 'page_id': self.page1.id, 'question': 'Q1', 'question_type': 'textbox', 'validation_required': True, 'validation_length_min': 2, 'validation_length_max': 8, 'validation_error_msg': "Error"})] results = [('test @ testcom', _('This answer must be an email address')), ('t', 'Error')] @@ -91,7 +91,7 @@ class TestSurvey(TransactionCase): def test_04_question_numerical_box(self): question = self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': 'numerical_box', 'validation_required': True, + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'numerical_box', 'validation_required': True, 'validation_min_float_value': 2.1, 'validation_max_float_value': 3.0, 'validation_error_msg': "Error"}) answer_tag = '%s_%s_%s' % (self.survey1.id, self.page1.id, question.id) results = [('aaa', _('This is not a number')), ('4.5', 'Error'), ('0.1', 'Error')] @@ -101,7 +101,7 @@ class TestSurvey(TransactionCase): def test_05_question_date(self): question = self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': 'date', 'validation_required': True, + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'date', 'validation_required': True, 'validation_min_date': '2015-03-20', 'validation_max_date': '2015-03-25', 'validation_error_msg': "Error"}) answer_tag = '%s_%s_%s' % (self.survey1.id, self.page1.id, question.id) results = [('2015-55-10', _('This is not a date')), ('2015-03-19', 'Error'), ('2015-03-26', 'Error')] @@ -113,7 +113,7 @@ class TestSurvey(TransactionCase): # Case-1: Executing action with correct data. correct_survey = self.env['survey.survey'].sudo(self.survey_manager).create({ 'title': "S0", 'stage_id': self.env['survey.stage'].search([('sequence', '=', 1)]).id, - 'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'type': 'free_text'})]})]}) + 'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'question_type': 'free_text'})]})]}) action = correct_survey.action_send_survey() template = self.env.ref('survey.email_template_survey', raise_if_not_found=False) @@ -143,7 +143,7 @@ class TestSurvey(TransactionCase): 'title': "Test survey"}), self.env['survey.survey'].sudo(self.survey_manager).create({ # Closed Survey. 'title': "S0", 'stage_id': self.env['survey.stage'].search([('closed', '=', True)]).id, # Getting Closed stage id. - 'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'type': 'free_text'})]})]})] + 'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'question_type': 'free_text'})]})]})] for survey in surveys: self.assertRaises(UserError, survey.action_send_survey) @@ -215,7 +215,7 @@ class TestSurvey(TransactionCase): def test_10_survey_result_simple_multiple_choice(self): question = self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': 'simple_choice', + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'simple_choice', 'labels_ids': [(0, 0, {'value': "Choice0", 'quizz_mark': 0}), (0, 0, {'value': "Choice1", 'quizz_mark': 0})]}) for i in range(3): self.env['survey.user_input'].sudo(self.user_public).create({'survey_id': self.survey1.id, 'user_input_line_ids': [(0, 0, { @@ -229,7 +229,7 @@ class TestSurvey(TransactionCase): def test_11_survey_result_matrix(self): question = self.env['survey.question'].sudo(self.survey_manager).create({ - 'page_id': self.page1.id, 'question': 'Q0', 'type': 'matrix', 'matrix_subtype': 'simple', + 'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'matrix', 'matrix_subtype': 'simple', 'labels_ids': [(0, 0, {'value': "Column0", "quizz_mark": 0}), (0, 0, {'value': "Column1", "quizz_mark": 0})], 'labels_ids_2': [(0, 0, {'value': "Row0", "quizz_mark": 0}), (0, 0, {'value': "Row1", "quizz_mark": 0})]}) for i in range(3): @@ -243,7 +243,7 @@ class TestSurvey(TransactionCase): self.assertEqual(self.env['survey.survey'].prepare_result(question)['result'], res, msg="Statistics of matrix type questions are different from expectations") def test_12_survey_result_numeric_box(self): - question = self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'type': 'numerical_box'}) + question = self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'numerical_box'}) num = [float(n) for n in random.sample(range(1, 100), 3)] nsum = sum(num) for i in range(3): @@ -257,7 +257,7 @@ class TestSurvey(TransactionCase): self.assertEqual(result[key], exresult[key], msg="Statistics of numeric box type questions are different from expectations") def test_13_survey_actions(self): - self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'type': 'numerical_box'}) + self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'numerical_box'}) actions = { 'start': {'method': 'public', 'token': '/test', 'text': 'Start'}, diff --git a/addons/survey/views/survey_result.xml b/addons/survey/views/survey_result.xml index 69190c195cc..38e784e1e52 100644 --- a/addons/survey/views/survey_result.xml +++ b/addons/survey/views/survey_result.xml @@ -37,11 +37,11 @@

Question - + Matrix: - - + + Answered @@ -52,16 +52,16 @@
- + - + - + - + @@ -88,17 +88,17 @@ - +
- +
- +
@@ -136,12 +136,12 @@
-
+
-
+
diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 131c5c75a60..dd7fc367c94 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -190,13 +190,13 @@ *

- - - - - - - + + + + + + +
@@ -356,13 +356,13 @@
- - - - - - - + + + + + + +
diff --git a/addons/survey/views/survey_views.xml b/addons/survey/views/survey_views.xml index 1ffc25eb948..7a31b4784f0 100644 --- a/addons/survey/views/survey_views.xml +++ b/addons/survey/views/survey_views.xml @@ -337,7 +337,7 @@ - +
@@ -406,42 +406,42 @@ - +
-
+
-
+
-
+
123..
-
+

YYYY-MM-DD

-
+
answer
answer
answer
-
+
answer
answer
answer
-
+
ans
@@ -472,10 +472,10 @@ - -