Esempio n. 1
0
def get_select_chain_with_sessions(app, module, include_self=True):
    select_chain = []
    if include_self:
        if module.is_multi_select():
            select_chain.append((module, 'selected_cases'))
        else:
            select_chain.append((module, 'case_id'))
    current_module = module
    case_type = module.case_type
    i = len(select_chain)
    while hasattr(current_module, 'parent_select') and current_module.parent_select.active:
        is_other_relation = current_module.parent_select.relationship is None
        parent_module = app.get_module_by_unique_id(
            current_module.parent_select.module_id,
            error=_("Case list used by parent child selection in '{}' not found").format(
                current_module.default_name()),
        )
        if is_other_relation and case_type == parent_module.case_type:
            session_var = 'case_id_' + case_type
        else:
            if current_module.is_multi_select():
                session_var = ('parent_' * i) + 'selected_cases'
            else:
                session_var = ('parent_' * i or 'case_') + 'id'
        if parent_module in [m for (m, _) in select_chain]:
            raise SuiteValidationError("Circular reference in case hierarchy")
        select_chain.append((parent_module, session_var))

        # update vars for next loop
        current_module = parent_module
        case_type = parent_module.case_type
        i += 1
    return select_chain
Esempio n. 2
0
    def _get_custom_xml_detail(self, module, detail, detail_type):
        d = load_xmlobject_from_string(detail.custom_xml, xmlclass=Detail)

        expected = id_strings.detail(module, detail_type)
        if not id_strings.is_custom_app_string(d.id) and d.id != expected:
            raise SuiteValidationError(
                "Menu {}, \"{}\", uses custom case list xml. The "
                "specified detail ID is '{}', expected '{}'".format(
                    module.id, module.default_name(), d.id, expected))

        return d
Esempio n. 3
0
 def get_datums_meta_for_form_generic(self, form, module=None):
     if not module:
         module = form.get_module()
     if form.form_type == 'module_form':
         datums_meta = self.get_case_datums_basic_module(module, form)
     elif form.form_type == 'advanced_form':
         datums_meta, _ = self.get_datum_meta_assertions_advanced(module, form)
         datums_meta.extend(EntriesHelper.get_new_case_id_datums_meta(form))
     else:
         raise SuiteValidationError("Unexpected form type '{}' with a case list form: {}".format(
             form.form_type, form.unique_id
         ))
     return datums_meta
Esempio n. 4
0
def get_select_chain(app, module, include_self=True):
        select_chain = [module] if include_self else []
        current_module = module
        while hasattr(current_module, 'parent_select') and current_module.parent_select.active:
            current_module = app.get_module_by_unique_id(
                current_module.parent_select.module_id,
                error=_("Case list used by parent child selection in '{}' not found").format(
                      current_module.default_name()),
            )
            if current_module in select_chain:
                raise SuiteValidationError("Circular reference in case hierarchy")
            select_chain.append(current_module)
        return select_chain
Esempio n. 5
0
 def get_datums_matched_to_manual_values(target_frame_elements, manual_values):
     """
     Attempt to match the target session variables with ones that the user
     has entered manually
     """
     manual_values_by_name = {datum.name: datum.xpath for datum in manual_values}
     for child in target_frame_elements:
         if not isinstance(child, WorkflowDatumMeta) or not child.requires_selection:
             yield child
         else:
             manual_value = manual_values_by_name.get(child.id)
             if manual_value:
                 yield StackDatum(id=child.id, value=manual_value)
             else:
                 raise SuiteValidationError("Unable to link forms, missing form variable: {}".format(
                     child.id
                 ))
Esempio n. 6
0
        def add_datums_for_target(module, source_form_dm, allow_missing=False):
            """
            Given a target module and a list of datums from the source module add children
            to the stack frames that are required by the target module and present in the source datums
            list.
            """
            target_form_dm = self.helper.get_frame_children(module.get_form(0),
                                                            module_only=True)

            used = set()

            for source_meta in source_form_dm:
                if source_meta.case_type:
                    # This is true for registration forms where the case being created is a subcase
                    target_dm = self.get_target_dm(target_form_dm,
                                                   source_meta.case_type,
                                                   module)
                    if target_dm:
                        used.add(source_meta)
                        meta = WorkflowDatumMeta.from_session_datum(
                            source_meta)
                        frame_case_created.add_child(
                            meta.to_stack_datum(datum_id=target_dm.id))
                        frame_case_not_created.add_child(
                            meta.to_stack_datum(datum_id=target_dm.id))
                else:
                    source_case_type = self.get_case_type_created_by_form(
                        form, target_module)
                    target_dm = self.get_target_dm(target_form_dm,
                                                   source_case_type, module)
                    if target_dm:
                        used.add(source_meta)
                        datum_meta = WorkflowDatumMeta.from_session_datum(
                            target_dm)
                        frame_case_created.add_child(
                            datum_meta.to_stack_datum(
                                source_id=source_meta.id))
                    elif not allow_missing:
                        raise SuiteValidationError(
                            u"The '{}' module is not properly configured to have a Case List Registration Form. "
                            u"All forms in the module should have the same case management configuration."
                            .format(module.default_name()))

            # return any source datums that were not already added to the target
            return [dm for dm in source_form_dm if dm not in used]
Esempio n. 7
0
def validate_suite(suite):
    if isinstance(suite, six.text_type):
        suite = suite.encode('utf8')
    if isinstance(suite, str):
        suite = etree.fromstring(suite)
    if isinstance(suite, etree._Element):
        suite = Suite(suite)
    assert isinstance(suite, Suite),\
        'Could not convert suite to a Suite XmlObject: %r' % suite

    def is_unique_list(things):
        return len(set(things)) == len(things)

    for detail in suite.details:
        orders = [field.sort_node.order for field in detail.fields
                  if field and field.sort_node]
        if not is_unique_list(orders):
            raise SuiteValidationError('field/sort/@order must be unique per detail')
Esempio n. 8
0
    def get_section_elements(self):
        def include_sort(detail_type, detail):
            return detail_type.endswith(
                'short') or detail.sort_nodeset_columns_for_detail()

        r = []
        if not self.app.use_custom_suite:
            for module in self.modules:
                for detail_type, detail, enabled in module.get_details():
                    if enabled:
                        if detail.custom_xml:
                            d = load_xmlobject_from_string(detail.custom_xml,
                                                           xmlclass=Detail)
                            expected = id_strings.detail(module, detail_type)
                            if not id_strings.is_custom_app_string(
                                    d.id) and d.id != expected:
                                raise SuiteValidationError(
                                    "Menu {}, \"{}\", uses custom case list xml. The "
                                    "specified detail ID is '{}', expected '{}'"
                                    .format(module.id, module.default_name(),
                                            d.id, expected))
                            r.append(d)
                        else:
                            detail_column_infos = get_detail_column_infos(
                                detail_type,
                                detail,
                                include_sort=include_sort(detail_type, detail),
                            )  # list of DetailColumnInfo named tuples
                            if detail_column_infos:
                                if detail.use_case_tiles:
                                    helper = CaseTileHelper(
                                        self.app, module, detail, detail_type,
                                        self.build_profile_id)
                                    r.append(helper.build_case_tile_detail())
                                else:
                                    print_template_path = None
                                    if detail.print_template:
                                        print_template_path = detail.print_template[
                                            'path']
                                    locale_id = id_strings.detail_title_locale(
                                        detail_type)
                                    title = Text(locale_id=locale_id
                                                 ) if locale_id else Text()
                                    d = self.build_detail(
                                        module,
                                        detail_type,
                                        detail,
                                        detail_column_infos,
                                        tabs=list(detail.get_tabs()),
                                        id=id_strings.detail(
                                            module, detail_type),
                                        title=title,
                                        print_template=print_template_path,
                                    )
                                    if d:
                                        r.append(d)
                        # add the persist case context if needed and if
                        # case tiles are present and have their own persistent block
                        if (detail.persist_case_context
                                and not (detail.use_case_tiles
                                         and detail.persist_tile_on_forms)):
                            d = self._get_persistent_case_context_detail(
                                module, detail.persistent_case_context_xml)
                            r.append(d)
                if module.fixture_select.active:
                    d = self._get_fixture_detail(module)
                    r.append(d)
        return r