Beispiel #1
0
    def test_first_group_id(self):
        survey = load_schema_file("test_repeating_household.json")

        first_group_id = "multiple-questions-group"

        self.assertEqual(SchemaHelper.get_first_group_id(survey),
                         first_group_id)
Beispiel #2
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
    def get_routing_path(self, group_id=None, group_instance=0):
        """
        Returns a list of the block ids visited based on answers provided
        :return: List of block location dicts
        """
        if group_id is None:
            group_id = SchemaHelper.get_first_group_id(self.survey_json)

        first_block_in_group = SchemaHelper.get_first_block_id_for_group(
            self.survey_json, group_id)
        location = Location(group_id, group_instance, first_block_in_group)

        return self.build_path(self.get_blocks(), location)
Beispiel #4
0
def post_interstitial(eq_id, form_type, collection_id, block_id):  # pylint: disable=unused-argument
    path_finder = PathFinder(g.schema_json, get_answer_store(current_user), get_metadata(current_user))
    q_manager = get_questionnaire_manager(g.schema, g.schema_json)

    this_location = Location(SchemaHelper.get_first_group_id(g.schema_json), group_instance=0, block_id=block_id)

    q_manager.update_questionnaire_store(this_location)

    # Don't care if data is valid because there isn't any for interstitial
    if this_location not in path_finder.get_location_path():
        _render_schema(this_location)
        return _build_template(current_location=this_location, context=q_manager.block_state, template='questionnaire')

    next_location = path_finder.get_next_location(current_location=this_location)

    if next_location is None:
        raise NotFound

    metadata = get_metadata(current_user)
    logger.info("Redirecting user to next location %s with tx_id=%s", str(next_location), metadata["tx_id"])
    return redirect(next_location.url(metadata))
def post_interstitial(eq_id, form_type, collection_id, block_id):  # pylint: disable=unused-argument
    path_finder = PathFinder(g.schema_json, get_answer_store(current_user), get_metadata(current_user))

    current_location = Location(SchemaHelper.get_first_group_id(g.schema_json), 0, block_id)

    valid_location = current_location in path_finder.get_location_path()
    questionnaire_store = get_questionnaire_store(current_user.user_id, current_user.user_ik)
    update_questionnaire_store_with_form_data(questionnaire_store, current_location, request.form.to_dict())

    # Don't care if data is valid because there isn't any for interstitial
    if not valid_location:
        block = _render_schema(current_location)
        return _build_template(current_location=current_location, context={"block": block}, template='questionnaire')

    next_location = path_finder.get_next_location(current_location=current_location)

    if next_location is None:
        raise NotFound

    metadata = get_metadata(current_user)
    next_location_url = next_location.url(metadata)
    logger.debug("redirecting", url=next_location_url)
    return redirect(next_location_url)
def get_introduction(eq_id, form_type, collection_id):  # pylint: disable=unused-argument
    group_id = SchemaHelper.get_first_group_id(g.schema_json)
    current_location = Location(group_id, group_instance=0, block_id='introduction')
    return _build_template(current_location, get_introduction_context(g.schema_json))