Example #1
0
    def get_location_path(self, group_id=None, group_instance=0):
        """
        Returns a list of url locations visited based on answers provided
        :return: List of block location dicts, with preceeding/closing interstitial pages included
        """
        if group_id is None:
            group_id = SchemaHelper.get_first_group_id(self.survey_json)

        routing_path = self.get_routing_path(group_id, group_instance)
        can_reach_summary = self.can_reach_summary(routing_path)

        location_path = [
            Location(group_id, 0, block_id)
            for block_id in self.preceeding_path
        ]

        location_path += routing_path

        if can_reach_summary:
            for block_id in PathFinder.CLOSING_INTERSTITIAL_PATH:
                location_path.append(
                    Location(SchemaHelper.get_last_group_id(self.survey_json),
                             0, block_id))

        return location_path
Example #2
0
def get_thank_you(eq_id, form_type, collection_id):  # pylint: disable=unused-argument
    group_id = SchemaHelper.get_last_group_id(g.schema_json)
    current_location = Location(group_id, group_instance=0, block_id='thank-you')
    thank_you_page = _build_template(current_location=current_location)
    # Delete user data on request of thank you page.
    _delete_user_data()
    return thank_you_page
Example #3
0
    def build_navigation(self, current_group_id, current_group_instance):
        """
        Build navigation based on the current group/instance selected

        :param current_group_id:
        :param current_group_instance:
        :return:
        """
        if self.survey_json.get('navigation', False) is False:
            return None

        navigation = []

        last_group_id = SchemaHelper.get_last_group_id(self.survey_json)

        for group in filter(lambda x: 'hide_in_navigation' not in x,
                            self.survey_json['groups']):
            logger.debug("building frontend navigation", group_id=group['id'])

            first_location = Location(group['id'], 0, group['blocks'][0]['id'])
            last_block_in_group = SchemaHelper.get_last_block_in_group(group)

            is_summary_or_confirm_group = last_block_in_group and \
                SchemaHelper.is_summary_or_confirmation(last_block_in_group)

            last_block_location = Location(group['id'], 0,
                                           last_block_in_group['id'])
            can_get_to_summary = is_summary_or_confirm_group and self.routing_path and \
                last_block_location in self.routing_path

            skip_group = self._should_skip_group(current_group_instance, group)
            if not skip_group:
                repeating_rule = SchemaHelper.get_repeat_rule(group)
                if repeating_rule:
                    logger.debug("building repeating navigation",
                                 group_id=group['id'])
                    navigation.extend(
                        self._build_repeating_navigation(
                            repeating_rule, group, current_group_id,
                            current_group_instance))
                elif last_group_id == group['id'] and can_get_to_summary:
                    logger.debug("building navigation", group_id=group['id'])
                    if len(self.completed_blocks) > 0 and set(
                            self.routing_path[:-1]).issubset(
                                self.completed_blocks):
                        navigation.append(
                            self._build_single_navigation(
                                group, current_group_id, first_location))
                elif last_group_id != group[
                        'id'] and not is_summary_or_confirm_group:
                    logger.debug("building navigation", group_id=group['id'])
                    navigation.append(
                        self._build_single_navigation(group, current_group_id,
                                                      first_location))

        return navigation
Example #4
0
    def test_last_group_id(self):
        survey = load_schema_file("test_repeating_household.json")

        last_group_id = "summary-group"

        self.assertEqual(last_group_id, SchemaHelper.get_last_group_id(survey))