Exemplo n.º 1
0
def get_block_handler(
    schema,
    block_id,
    list_item_id,
    questionnaire_store,
    language,
    list_name=None,
    to_list_item_id=None,
    request_args=None,
    form_data=None,
):
    block = schema.get_block(block_id)

    if not block:
        raise InvalidLocationException(
            f"block id {block_id} is not valid for this schema"
        )

    if schema.is_block_in_repeating_section(block_id=block["id"]) and not all(
        (list_name, list_item_id)
    ):
        raise InvalidLocationException(
            f"block id {block_id} is in a repeating section without valid list_name/list_item_id"
        )

    block_type = block["type"]
    block_class = BLOCK_MAPPINGS.get(block_type)
    if not block_class:
        raise ValueError(f"block type {block_type} is not valid")

    section_id = schema.get_section_id_for_block_id(block_id)

    if to_list_item_id:
        location = RelationshipLocation(
            section_id=section_id,
            block_id=block_id,
            list_item_id=list_item_id,
            to_list_item_id=to_list_item_id,
            list_name=list_name,
        )
    else:
        location = Location(
            section_id=section_id,
            block_id=block_id,
            list_name=list_name,
            list_item_id=list_item_id,
        )

    return block_class(
        schema, questionnaire_store, language, location, request_args, form_data
    )
Exemplo n.º 2
0
    def __init__(self, schema, questionnaire_store, section_id, list_item_id, language):
        self._schema = schema
        self._questionnaire_store = questionnaire_store
        self._section_id = section_id
        self._list_item_id = list_item_id
        self._language = language
        self._router = Router(
            schema,
            questionnaire_store.answer_store,
            questionnaire_store.list_store,
            questionnaire_store.progress_store,
            questionnaire_store.metadata,
            questionnaire_store.response_metadata,
        )
        if not self._is_valid_location():
            raise InvalidLocationException(f"location {self._section_id} is not valid")

        self.current_location = Location(
            section_id=self._section_id,
            list_name=self._schema.get_repeating_list_for_section(self._section_id),
            list_item_id=self._list_item_id,
        )

        self._routing_path = self._router.routing_path(
            section_id=self._section_id, list_item_id=self._list_item_id
        )
    def __init__(
        self,
        schema: QuestionnaireSchema,
        questionnaire_store: QuestionnaireStore,
        language: str,
        current_location: Union[Location, RelationshipLocation],
        request_args: MutableMapping,
        form_data: MutableMapping,
    ):
        self._schema = schema
        self._questionnaire_store = questionnaire_store
        self._language = language
        self._current_location = current_location
        self._request_args = request_args or {}
        self._form_data = form_data

        self.block = self._schema.get_block(current_location.block_id)
        self._routing_path = self._get_routing_path()
        self.page_title = None
        self._return_to = request_args.get("return_to")
        self.resume = "resume" in request_args

        if not self.is_location_valid():
            raise InvalidLocationException(
                f"location {self._current_location} is not valid")
Exemplo n.º 4
0
    def __init__(
        self,
        schema: QuestionnaireSchema,
        questionnaire_store: QuestionnaireStore,
        language: str,
    ):
        if not schema.is_flow_linear:
            raise InvalidLocationException("Submit page not enabled")

        self._schema = schema
        self._questionnaire_store = questionnaire_store
        self._language = language
Exemplo n.º 5
0
    def _resolve_list_item_id_for_value_source(
            self, value_source: dict) -> Optional[str]:
        list_item_id: Optional[str] = None

        if list_item_selector := value_source.get("list_item_selector"):
            if list_item_selector["source"] == "location":
                if not self.location:
                    raise InvalidLocationException(
                        "list_item_selector source location used without location"
                    )

                list_item_id = getattr(self.location,
                                       list_item_selector["identifier"])

            elif list_item_selector["source"] == "list":
                list_item_id = getattr(
                    self.list_store[list_item_selector["identifier"]],
                    list_item_selector["selector"],
                )
Exemplo n.º 6
0
    def __init__(
        self, schema, questionnaire_store, language, current_location, request_args
    ):
        self._schema = schema
        self._questionnaire_store = questionnaire_store
        self._language = language
        self._current_location = current_location
        self._request_args = request_args or {}
        self.block = self._schema.get_block(current_location.block_id)

        self._questionnaire_store_updater = None
        self._placeholder_renderer = None
        self._router = None
        self._routing_path = self._get_routing_path()
        self.form = None
        self.page_title = None

        if not self.is_location_valid():
            raise InvalidLocationException(
                f"location {self._current_location} is not valid"
            )