def _build_repeating_navigation(self, repeating_rule, section,
                                    current_group_id, current_group_instance):
        groups = section['groups']
        answer_ids_on_path = get_answer_ids_on_routing_path(
            self.schema, self.routing_path)
        no_of_repeats = evaluate_repeat(repeating_rule, self.answer_store,
                                        answer_ids_on_path)

        repeating_nav = []
        if repeating_rule['type'] == 'answer_count':
            link_names = self._generate_link_names(
                section['title_from_answers'])

            for group in groups:
                is_current_group = group['id'] == current_group_id
                repeating_nav += self._generate_repeated_items(
                    link_names, group, no_of_repeats, is_current_group,
                    current_group_instance)

        elif no_of_repeats > 0:
            target_location = self._get_location_for_section(section, groups)
            item = self._build_single_repeating_navigation(
                section, current_group_id, target_location)
            repeating_nav.append(item)

        return repeating_nav
Exemplo n.º 2
0
def _get_schema_context(full_routing_path, group_instance, metadata,
                        answer_store, schema):
    answer_ids_on_path = get_answer_ids_on_routing_path(
        schema, full_routing_path)

    return build_schema_context(metadata=metadata,
                                schema=schema,
                                answer_store=answer_store,
                                group_instance=group_instance,
                                answer_ids_on_path=answer_ids_on_path)
    def test_should_repeat_for_answer_until(self):
        questionnaire = {
            'survey_id': '021',
            'data_version': '0.0.1',
            'sections': [{
                'id': 'section1',
                'groups': [
                    {
                        'id': 'group-1',
                        'blocks': [
                            {
                                'id': 'block-1',
                                'questions': [{
                                    'id': 'question-2',
                                    'answers': [
                                        {
                                            'id': 'my_answer',
                                            'type': 'TextField'
                                        }
                                    ]
                                }]
                            }
                        ]
                    }
                ]
            }]
        }

        schema = QuestionnaireSchema(questionnaire)

        # Given
        repeat = {
            'type': 'until',
            'when': [
                {
                    'id': 'my_answer',
                    'condition': 'equals',
                    'value': 'Done'
                }
            ]
        }

        answer_store = AnswerStore({})
        current_path = [Location('group-1', 0, 'block-1')]
        answer_on_path = get_answer_ids_on_routing_path(schema, current_path)

        self.assertEqual(evaluate_repeat(repeat, answer_store, answer_on_path), 1)

        answer_store.add(Answer(answer_id='my_answer', value='Not Done', group_instance=0))
        self.assertEqual(evaluate_repeat(repeat, answer_store, answer_on_path), 2)

        answer_store.add(Answer(answer_id='my_answer', value='Done', group_instance=1))
        self.assertEqual(evaluate_repeat(repeat, answer_store, answer_on_path), 2)
Exemplo n.º 4
0
def _get_schema_context(full_routing_path, location, metadata,
                        collection_metadata, answer_store, schema):
    answer_ids_on_path = get_answer_ids_on_routing_path(
        schema, full_routing_path)
    group_instance_id = get_group_instance_id(schema, answer_store,
                                              location) if location else None

    return build_schema_context(
        metadata=metadata,
        collection_metadata=collection_metadata,
        schema=schema,
        answer_store=answer_store,
        group_instance=location.group_instance if location else 0,
        group_instance_id=group_instance_id,
        answer_ids_on_path=answer_ids_on_path)
    def test_should_minus_one_from_maximum_repeats(self):
        questionnaire = {
            'survey_id': '021',
            'data_version': '0.0.1',
            'sections': [{
                'id': 'section1',
                'groups': [
                    {
                        'id': 'group-1',
                        'blocks': [
                            {
                                'id': 'block-1',
                                'questions': [{
                                    'id': 'question-2',
                                    'answers': [
                                        {
                                            'id': 'my_answer',
                                            'type': 'TextField'
                                        }
                                    ]
                                }]
                            }
                        ]
                    }
                ]
            }]
        }

        schema = QuestionnaireSchema(questionnaire)

        # Given
        repeat = {
            'answer_id': 'my_answer',
            'type': 'answer_count_minus_one'
        }
        answer_store = AnswerStore({})
        for i in range(27):
            answer_store.add(Answer(answer_id='my_answer', value='3', answer_instance=i))

        current_path = [Location('group-1', 0, 'block-1')]

        # When
        answer_on_path = get_answer_ids_on_routing_path(schema, current_path)
        number_of_repeats = evaluate_repeat(repeat, answer_store, answer_on_path)

        self.assertEqual(number_of_repeats, 24)