Esempio n. 1
0
    def get_state_for_group(self, group, group_instance=None):
        if isinstance(group, str):
            # lookup group by group ID
            group = self.schema.get_group(group)

        cache_key = f'{group["id"]}-{group_instance}'
        group_state = self._group_states.get(cache_key)
        if group_state:
            return group_state

        if (QuestionnaireSchema.is_confirmation_group(group)
                or QuestionnaireSchema.is_summary_group(group)):
            # summary/confirmations are special cases as we don't want to
            # render until the whole survey is complete. They're also never
            # show as complete
            return self.NOT_STARTED if self.all_sections_complete(
            ) else self.SKIPPED

        if self._should_skip(group):
            return self.SKIPPED

        block_states = [
            state for location, state in self._get_block_states_for_group(
                group, group_instance)
        ]

        group_state = self._get_group_state_from_block_states(block_states)

        self._group_states[cache_key] = group_state
        return group_state
Esempio n. 2
0
    def get_state_for_group(self, group, group_instance=None):
        if isinstance(group, str):
            # lookup group by group ID
            group = self.schema.get_group(group)

        if (QuestionnaireSchema.is_confirmation_group(group)
                or QuestionnaireSchema.is_summary_group(group)):
            # summary/confirmations are special cases as we don't want to
            # render until the whole survey is complete. They're also never
            # show as complete
            return self.NOT_STARTED if self.all_sections_complete(
            ) else self.SKIPPED

        if self._should_skip(group):
            return self.SKIPPED

        block_states = [
            state for location, state in self._get_block_states_for_group(
                group, group_instance)
        ]

        def eval_state(state_to_compare):
            return (state == state_to_compare for state in block_states)

        group_state = self.NOT_STARTED

        if all(eval_state(self.SKIPPED)):
            group_state = self.SKIPPED

        elif not self.routing_path:
            group_state = self.NOT_STARTED

        elif all(eval_state(self.INVALID)):
            group_state = self.INVALID

        elif all(state in self.COMPLETED_STATES for state in block_states):
            group_state = self.COMPLETED

        elif any(eval_state(self.COMPLETED)):
            group_state = self.STARTED

        return group_state
    def test_is_confirmation(self):
        survey_json = {
            'sections': [{
                'id': 'section-1',
                'groups': [{
                    'id': 'group-1',
                    'blocks': [
                        {
                            'id': 'block-1',
                            'type': 'Confirmation'
                        }
                    ]
                }]
            }]
        }

        schema = QuestionnaireSchema(survey_json)
        self.assertTrue(schema.is_confirmation_section(schema.get_section('section-1')))
        self.assertTrue(schema.is_confirmation_group(schema.get_group('group-1')))
        self.assertFalse(schema.is_summary_section(schema.get_section('section-1')))
        self.assertFalse(schema.is_summary_group(schema.get_group('group-1')))