示例#1
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)
                            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
示例#2
0
 def active_details(self):
     return {
         id_strings.detail(module, detail_type)
         for module in self.modules
         for detail_type, detail, enabled in module.get_details()
         if enabled and detail.columns
     }
示例#3
0
 def active_details(self):
     return {
         id_strings.detail(module, detail_type)
         for module in self.modules
         for detail_type, detail, enabled in module.get_details()
         if enabled and detail.columns
     }
示例#4
0
 def get_detail_persistent_attr(self, module, detail_module, detail_type="case_short"):
     detail, detail_enabled = self._get_detail_from_module(module, detail_type)
     if detail_enabled:
         # if configured to use persisted case tile context from another module which has case tiles
         # configured then get id_string for that module
         if detail.persistent_case_tile_from_module:
             module_for_persistent_context = self._get_module_for_persistent_context(
                 module, detail.persistent_case_tile_from_module
             )
             if module_for_persistent_context:
                 return id_strings.detail(module_for_persistent_context, detail_type)
         if self._has_persistent_tile(detail):
             return id_strings.detail(detail_module, detail_type)
         if detail.persist_case_context and detail_type == "case_short":
             # persistent_case_context will not work on product lists.
             return id_strings.persistent_case_context_detail(detail_module)
     return None
示例#5
0
 def get_detail_persistent_attr(self, module, detail_module, detail_type="case_short"):
     detail, detail_enabled = self._get_detail_from_module(module, detail_type)
     if detail_enabled:
         # if configured to use persisted case tile context from another module which has case tiles
         # configured then get id_string for that module
         if detail.persistent_case_tile_from_module:
             module_for_persistent_context = self._get_module_for_persistent_context(
                 module, detail.persistent_case_tile_from_module
             )
             if module_for_persistent_context:
                 return id_strings.detail(module_for_persistent_context, detail_type)
         if self._has_persistent_tile(detail):
             return id_strings.detail(detail_module, detail_type)
         if detail.persist_case_context and detail_type == "case_short":
             # persistent_case_context will not work on product lists.
             return id_strings.persistent_case_context_detail(detail_module)
     return None
示例#6
0
 def _get_base_context(self):
     """
     Get the basic context variables for interpolation into the
     case tile detail template string
     """
     return {
         "detail_id": id_strings.detail(self.module, self.detail_type),
         "title_text_id": id_strings.detail_title_locale(self.detail_type),
     }
示例#7
0
 def get_detail_persistent_attr(self, module, detail_module, detail_type="case_short"):
     detail, detail_enabled = self._get_detail_from_module(module, detail_type)
     if detail_enabled:
         if self._has_persistent_tile(detail):
             return id_strings.detail(detail_module, detail_type)
         if detail.persist_case_context and detail_type == "case_short":
             # persistent_case_context will not work on product lists.
             return id_strings.persistent_case_context_detail(detail_module)
     return None
示例#8
0
 def get_detail_persistent_attr(self, module, detail_module, detail_type="case_short"):
     detail, detail_enabled = self._get_detail_from_module(module, detail_type)
     if detail_enabled:
         if self._has_persistent_tile(detail):
             return id_strings.detail(detail_module, detail_type)
         if detail.persist_case_context and detail_type == "case_short":
             # persistent_case_context will not work on product lists.
             return id_strings.persistent_case_context_detail(detail_module)
     return None
示例#9
0
 def _get_base_context(self):
     """
     Get the basic context variables for interpolation into the
     case tile detail template string
     """
     return {
         "detail_id": id_strings.detail(self.module, self.detail_type),
         "title_text_id": id_strings.detail_title_locale(self.detail_type),
     }
示例#10
0
 def get_case_tile_datum_attrs(self, module, detail_module):
     detail_persistent = None
     detail_inline = None
     for detail_type, detail, enabled in module.get_details():
         if detail.persist_tile_on_forms and (detail.use_case_tiles or detail.custom_xml) and enabled:
             detail_persistent = id_strings.detail(detail_module, detail_type)
             if detail.pull_down_tile:
                 detail_inline = self.details_helper.get_detail_id_safe(detail_module, "case_long")
             break
     return detail_persistent, detail_inline
示例#11
0
    def get_section_elements(self):
        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
                            )
                            r.append(d)
                        else:
                            detail_column_infos = get_detail_column_infos(
                                detail,
                                include_sort=detail_type.endswith('short'),
                            )
                            if detail_column_infos:
                                if detail.use_case_tiles:
                                    r.append(self.build_case_tile_detail(
                                        module, detail, detail_type
                                    ))
                                else:
                                    d = self.build_detail(
                                        module,
                                        detail_type,
                                        detail,
                                        detail_column_infos,
                                        list(detail.get_tabs()),
                                        id_strings.detail(module, detail_type),
                                        Text(locale_id=id_strings.detail_title_locale(
                                            module, detail_type
                                        )),
                                        0,
                                        len(detail_column_infos)
                                    )
                                    if d:
                                        r.append(d)
                if module.fixture_select.active:
                    d = Detail(
                        id=id_strings.fixture_detail(module),
                        title=Text(),
                    )
                    xpath = Xpath(function=module.fixture_select.display_column)
                    if module.fixture_select.localize:
                        template_text = Text(locale=Locale(child_id=Id(xpath=xpath)))
                    else:
                        template_text = Text(xpath_function=module.fixture_select.display_column)
                    fields = [Field(header=Header(text=Text()),
                                    template=Template(text=template_text),
                                    sort_node='')]

                    d.fields = fields
                    r.append(d)
        return r
示例#12
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
示例#13
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
                            )
                            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
示例#14
0
    def build_case_tile_detail(self, module, detail, detail_type):
        """
        Return a Detail node from an apps.app_manager.models.Detail that is
        configured to use case tiles.

        This method does so by injecting the appropriate strings into a template
        string.
        """
        from corehq.apps.app_manager.detail_screen import get_column_xpath_generator

        template_args = {
            "detail_id": id_strings.detail(module, detail_type),
            "title_text_id": id_strings.detail_title_locale(
                module, detail_type
            )
        }
        # Get field/case property mappings

        cols_by_tile = {col.case_tile_field: col for col in detail.columns}
        for template_field in ["header", "top_left", "sex", "bottom_left", "date"]:
            column = cols_by_tile.get(template_field, None)
            if column is None:
                raise SuiteError(
                    'No column was mapped to the "{}" case tile field'.format(
                        template_field
                    )
                )
            template_args[template_field] = {
                "prop_name": get_column_xpath_generator(
                    self.app, module, detail, column
                ).xpath,
                "locale_id": id_strings.detail_column_header_locale(
                    module, detail_type, column,
                ),
                # Just using default language for now
                # The right thing to do would be to reference the app_strings.txt I think
                "prefix": escape(
                    column.header.get(self.app.default_language, "")
                )
            }
            if column.format == "enum":
                template_args[template_field]["enum_keys"] = {}
                for mapping in column.enum:
                    template_args[template_field]["enum_keys"][mapping.key] = \
                        id_strings.detail_column_enum_variable(
                            module, detail_type, column, mapping.key_as_variable
                        )
        # Populate the template
        detail_as_string = self._case_tile_template_string.format(**template_args)
        return load_xmlobject_from_string(detail_as_string, xmlclass=Detail)
示例#15
0
 def get_section_elements(self):
     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)
                         r.append(d)
                     else:
                         detail_column_infos = get_detail_column_infos(
                             detail,
                             include_sort=detail_type.endswith('short'),
                         )  # 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']
                                 d = self.build_detail(
                                     module,
                                     detail_type,
                                     detail,
                                     detail_column_infos,
                                     tabs=list(detail.get_tabs()),
                                     id=id_strings.detail(
                                         module, detail_type),
                                     title=Text(locale_id=id_strings.
                                                detail_title_locale(
                                                    module, detail_type)),
                                     print_template=print_template_path,
                                 )
                                 if d:
                                     r.append(d)
                     if detail.persist_case_context and not 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
示例#16
0
 def get_section_elements(self):
     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
                         )
                         r.append(d)
                     else:
                         detail_column_infos = get_detail_column_infos(
                             detail,
                             include_sort=detail_type.endswith('short'),
                         )
                         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:
                                 d = self.build_detail(
                                     module,
                                     detail_type,
                                     detail,
                                     detail_column_infos,
                                     tabs=list(detail.get_tabs()),
                                     id=id_strings.detail(module, detail_type),
                                     title=Text(locale_id=id_strings.detail_title_locale(
                                         module, detail_type
                                     )),
                                 )
                                 if d:
                                     r.append(d)
                     if detail.persist_case_context and not 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
示例#17
0
    def get_section_elements(self):
        def include_sort(detail_type, detail):
            return detail_type.endswith(
                'short') or detail.sort_nodeset_columns_for_detail()

        if self.app.use_custom_suite:
            return []

        elements = []
        for module in self.modules:
            for detail_type, detail, enabled in module.get_details():
                if not enabled:
                    continue

                if detail.custom_xml:
                    elements.append(
                        self._get_custom_xml_detail(module, detail,
                                                    detail_type))
                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)
                            elements.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:
                                elements.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)
                        elements.append(d)

            if module.fixture_select.active:
                d = self._get_fixture_detail(module)
                elements.append(d)

        if toggles.MOBILE_UCR.enabled(self.app.domain):
            if any([
                    getattr(m, 'report_context_tile', False)
                    for m in self.app.get_modules()
            ]):
                elements.append(self._get_report_context_tile_detail())

        return elements
示例#18
0
 def get_detail_id_safe(self, module, detail_type):
     detail_id = id_strings.detail(
         module=module,
         detail_type=detail_type,
     )
     return detail_id if detail_id in self.active_details else None
示例#19
0
 def get_detail_id_safe(self, module, detail_type):
     detail_id = id_strings.detail(
         module=module,
         detail_type=detail_type,
     )
     return detail_id if detail_id in self.active_details else None