Ejemplo n.º 1
0
    def get_agronomic_measures_picto_values(
            self, questiongroup: QuestionnaireQuestiongroup, values: dict,
            render_text: str):
        """
        Return a comma-separated list of values. If there is a sub-question, add
        it in brackets right after the corresponding value.
        """
        render_list = []

        main_question = questiongroup.get_question_by_key_keyword(
            'tech_measures_agronomic_sub')
        main_value_labels = dict(main_question.choices)

        sub_question_mapping = {
            'measures_agronomic_a3': 'tech_agronomic_tillage',
            'measures_agronomic_a6_residue_management': 'tech_residue_management',
        }

        for main_value in values.get('tech_measures_agronomic_sub', []):
            rendered_value = main_value_labels[main_value]
            if main_value in sub_question_mapping.keys():
                sub_keyword = sub_question_mapping[main_value]
                sub_question = questiongroup.get_question_by_key_keyword(
                    sub_keyword)
                sub_value = self._get_choice_label(
                    sub_question, values.get(sub_keyword))
                if sub_value:
                    rendered_value += f' ({sub_value})'
            render_list.append(rendered_value)
        return render_text + ' - ' + ', '.join(render_list)
Ejemplo n.º 2
0
    def get_agronomic_measures_picto_values(
            self, questiongroup: QuestionnaireQuestiongroup, values: dict,
            render_text: str):
        """
        Return a comma-separated list of values. If there is a sub-question, add
        it in brackets right after the corresponding value.
        """
        render_list = []

        main_question = questiongroup.get_question_by_key_keyword(
            'tech_measures_agronomic_sub')
        main_value_labels = dict(main_question.choices)

        sub_question_mapping = {
            'measures_agronomic_a3': 'tech_agronomic_tillage',
            'measures_agronomic_a6_residue_management':
            'tech_residue_management',
        }

        for main_value in values.get('tech_measures_agronomic_sub', []):
            rendered_value = main_value_labels[main_value]
            if main_value in sub_question_mapping.keys():
                sub_keyword = sub_question_mapping[main_value]
                sub_question = questiongroup.get_question_by_key_keyword(
                    sub_keyword)
                sub_value = self._get_choice_label(sub_question,
                                                   values.get(sub_keyword))
                if sub_value:
                    rendered_value += f' ({sub_value})'
            render_list.append(rendered_value)
        return render_text + ' - ' + ', '.join(render_list)
Ejemplo n.º 3
0
 def test_raises_error_if_max_num_smaller_than_1(self):
     configuration_dict = {
         "keyword": "qg_1",
         "form_options": {
             "max_num": -1
         },
         "questions": [{
             "keyword": "key_1"
         }]
     }
     with self.assertRaises(ConfigurationErrorInvalidConfiguration):
         QuestionnaireQuestiongroup(self.subcategory, configuration_dict)
Ejemplo n.º 4
0
 def test_raises_error_if_min_num_not_integer(self):
     configuration_dict = {
         "keyword": "qg_1",
         "form_options": {
             "min_num": "foo"
         },
         "questions": [{
             "keyword": "key_1"
         }]
     }
     with self.assertRaises(ConfigurationErrorInvalidConfiguration):
         QuestionnaireQuestiongroup(self.subcategory, configuration_dict)
Ejemplo n.º 5
0
 def test_raises_error_if_questions_not_list(self):
     configuration_dict = {"keyword": "qg_1", "questions": "foo"}
     with self.assertRaises(ConfigurationErrorInvalidConfiguration):
         QuestionnaireQuestiongroup(self.subcategory, configuration_dict)
Ejemplo n.º 6
0
 def test_raises_error_if_keyword_not_string(self):
     configuration_dict = {"keyword": ["bar"]}
     with self.assertRaises(ConfigurationErrorInvalidConfiguration):
         QuestionnaireQuestiongroup(self.subcategory, configuration_dict)