Esempio n. 1
0
    def get_previous_location(self, current_location):
        """
        Returns the previous 'location' to visit given a set of user answers
        :param current_location:
        :return: The previous location as a dict
        :return:
        """

        if current_location.group_id == 'who-lives-here-relationship':
            return self._relationship_previous_location(
                current_location.group_instance)

        is_first_block_for_group = SchemaHelper.is_first_block_id_for_group(
            self.survey_json, current_location.group_id,
            current_location.block_id)

        if is_first_block_for_group:
            return None

        routing_path = self.get_routing_path(current_location.group_id,
                                             current_location.group_instance)
        current_location_index = PathFinder._get_current_location_index(
            routing_path, current_location)

        if current_location_index is not None and current_location_index != 0:
            return routing_path[current_location_index - 1]
        return None
Esempio n. 2
0
def _build_template(current_location, context=None, template=None):
    metadata = get_metadata(current_user)
    metadata_context = build_metadata_context(metadata)

    answer_store = get_answer_store(current_user)
    completed_blocks = get_completed_blocks(current_user)

    navigation = Navigation(g.schema_json, answer_store, metadata, completed_blocks)
    front_end_navigation = navigation.build_navigation(current_location.group_id, current_location.group_instance)

    path_finder = PathFinder(g.schema_json, answer_store, metadata)
    previous_location = path_finder.get_previous_location(current_location)

    previous_url = None

    is_first_block_for_group = SchemaHelper.is_first_block_id_for_group(g.schema_json, current_location.group_id, current_location.block_id)

    if previous_location is not None and not is_first_block_for_group and not current_location.block_id == 'thank-you':
        previous_url = previous_location.url(metadata)

    return _render_template(context, current_location.block_id, front_end_navigation, metadata_context, current_location, previous_url, template)