Exemplo n.º 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
Exemplo n.º 2
0
def _create_custom_app_strings(app, lang):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            else:
                label = trans(module.referral_label)
            yield id_strings.detail_title_locale(module, detail_type), label

            for column in detail.get_columns():
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(module, detail_type, column, item.key), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(module, detail_type, column, index), trans(item.values)
                    for property, values in column.graph_configuration.locale_specific_config.iteritems():
                        yield id_strings.graph_configuration(module, detail_type, column, property), trans(values)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(module, detail_type, tab), trans(tab.header)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))
        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)
Exemplo n.º 3
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),
     }
Exemplo n.º 4
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),
     }
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
def _create_custom_app_strings(app, lang):
    from corehq.apps.app_manager.models import Module

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if LooseVersion(app.build_spec.version) >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            else:
                label = trans(module.referral_label)
            yield id_strings.detail_title_locale(module, detail_type), label

            detail_column_infos = get_detail_column_infos(detail, include_sort=detail_type == 'case_short')
            for (column, sort_element, order) in detail_column_infos:
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(module, detail_type, column, item.key), trans(item.value)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))
        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)
Exemplo n.º 8
0
def _create_custom_app_strings(app, lang):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            else:
                label = trans(module.referral_label)
            yield id_strings.detail_title_locale(module, detail_type), label

            for column in detail.get_columns():
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(module, detail_type, column, item.key), trans(item.value)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))
        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)
Exemplo n.º 9
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)
Exemplo n.º 10
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:
                                 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
Exemplo n.º 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:
                                 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
Exemplo n.º 12
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
Exemplo n.º 13
0
def _create_custom_app_strings(app, lang, for_default=False):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names and current language
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name
    yield id_strings.current_language(), lang

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            elif detail_type.startswith('referral'):
                label = trans(module.referral_label)
            elif detail_type in ('product_short', 'product_long'):
                label = ''
            else:
                label = None
            if label is not None:
                yield id_strings.detail_title_locale(module, detail_type), label

            for column in detail.get_columns():
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(
                            module, detail_type, column, item.key_as_variable
                        ), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(module, detail_type, column, index), trans(item.values)
                    for property, values in column.graph_configuration.locale_specific_config.iteritems():
                        yield id_strings.graph_configuration(module, detail_type, column, property), trans(values)
                    for index, item in enumerate(column.graph_configuration.series):
                        for property, values in item.locale_specific_config.iteritems():
                            yield id_strings.graph_series_configuration(
                                module, detail_type, column, index, property
                            ), trans(values)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(module, detail_type, tab), trans(tab.header)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))

        icon = module.icon_app_string(lang, for_default=for_default)
        audio = module.audio_app_string(lang, for_default=for_default)
        if icon:
            yield id_strings.module_icon_locale(module), icon
        if audio:
            yield id_strings.module_audio_locale(module), audio

        if hasattr(module, 'report_configs'):
            yield id_strings.report_menu(), 'Reports'
            yield id_strings.report_name_header(), 'Report Name'
            yield id_strings.report_description_header(), 'Report Description'
            yield id_strings.report_last_sync(), 'Last Sync'
            yield id_strings.report_data_table(), 'Data Table'
            for config in module.report_configs:
                yield id_strings.report_command(config.uuid), trans(config.header)
                yield id_strings.report_name(config.uuid), trans(config.header)
                yield id_strings.report_description(config.uuid), trans(config.localized_description)
                for column in config.report.report_columns:
                    yield (
                        id_strings.report_column_header(config.uuid, column.column_id),
                        column.get_header(lang)
                    )

        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
                icon = module.case_list.icon_app_string(lang, for_default=for_default)
                audio = module.case_list.audio_app_string(lang, for_default=for_default)
                if icon:
                    yield id_strings.case_list_icon_locale(module), icon
                if audio:
                    yield id_strings.case_list_audio_locale(module), audio

        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)

            icon = form.icon_app_string(lang, for_default=for_default)
            audio = form.audio_app_string(lang, for_default=for_default)
            if icon:
                yield id_strings.form_icon_locale(form), icon
            if audio:
                yield id_strings.form_audio_locale(form), audio

        if hasattr(module, 'case_list_form') and module.case_list_form.form_id:
            yield (
                id_strings.case_list_form_locale(module),
                trans(module.case_list_form.label) or "Create a new Case"
            )
            icon = module.case_list_form.icon_app_string(lang, for_default=for_default)
            audio = module.case_list_form.audio_app_string(lang, for_default=for_default)
            if icon:
                yield id_strings.case_list_form_icon_locale(module), icon
            if audio:
                yield id_strings.case_list_form_audio_locale(module), audio
Exemplo n.º 14
0
def _create_custom_app_strings(app, lang, for_default=False):
    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get(
                'properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features',
                               {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text, ) if not (
                    text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    if for_default:
        # include language code names and current language
        for lc in app.langs:
            name = langcodes.get_name(lc) or lc
            if not name:
                continue
            with localize(convert_to_two_letter_code(lc)):
                name = ugettext(name)
            yield lc, name

    yield id_strings.current_language(), lang

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            elif detail_type.startswith('referral'):
                label = trans(module.referral_label)
            elif detail_type in ('product_short', 'product_long'):
                label = ''
            else:
                label = None
            if label is not None:
                yield id_strings.detail_title_locale(module,
                                                     detail_type), label

            for column in detail.get_columns():
                yield id_strings.detail_column_header_locale(
                    module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(
                            module, detail_type, column,
                            item.key_as_variable), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(
                            column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(
                            module, detail_type, column,
                            index), trans(item.values)
                    for property, values in column.graph_configuration.locale_specific_config.iteritems(
                    ):
                        yield id_strings.graph_configuration(
                            module, detail_type, column,
                            property), trans(values)
                    for index, item in enumerate(
                            column.graph_configuration.series):
                        for property, values in item.locale_specific_config.iteritems(
                        ):
                            yield id_strings.graph_series_configuration(
                                module, detail_type, column, index,
                                property), trans(values)

            # To list app strings for properties used as sorting properties only
            if detail.sort_elements:
                sort_only, sort_columns = get_sort_and_sort_only_columns(
                    detail, detail.sort_elements)
                for field, sort_element, order in sort_only:
                    if sort_element.has_display_values():
                        column = create_temp_sort_column(sort_element, order)
                        yield id_strings.detail_column_header_locale(module, detail_type, column), \
                            trans(column.header)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(
                    module, detail_type, tab), trans(tab.header)

            if getattr(detail, 'lookup_display_results'):
                yield id_strings.callout_header_locale(module), trans(
                    detail.lookup_field_header)

        yield id_strings.module_locale(module), maybe_add_index(
            trans(module.name))

        icon = module.icon_app_string(lang, for_default=for_default)
        audio = module.audio_app_string(lang, for_default=for_default)
        if icon:
            yield id_strings.module_icon_locale(module), icon
        if audio:
            yield id_strings.module_audio_locale(module), audio

        if hasattr(module, 'report_configs'):
            yield id_strings.report_menu(), 'Reports'
            yield id_strings.report_name_header(), 'Report Name'
            yield id_strings.report_description_header(), 'Report Description'
            yield id_strings.report_last_sync(), 'Last Sync'
            yield id_strings.report_data_table(), 'Data Table'
            for config in module.report_configs:
                yield id_strings.report_command(config.uuid), trans(
                    config.header)
                yield id_strings.report_name(config.uuid), trans(config.header)
                yield id_strings.report_description(config.uuid), trans(
                    config.localized_description)
                for column in config.report(app.domain).report_columns:
                    yield (id_strings.report_column_header(
                        config.uuid,
                        column.column_id), column.get_header(lang))
                for chart_id, graph_config in config.complete_graph_configs.iteritems(
                ):
                    for index, item in enumerate(graph_config.annotations):
                        yield id_strings.mobile_ucr_annotation(
                            module, config.uuid, index), trans(item.values)
                    for property, values in graph_config.locale_specific_config.iteritems(
                    ):
                        yield id_strings.mobile_ucr_configuration(
                            module, config.uuid, property), trans(values)
                    for index, item in enumerate(graph_config.series):
                        for property, values in item.locale_specific_config.iteritems(
                        ):
                            yield id_strings.mobile_ucr_series_configuration(
                                module, config.uuid, index,
                                property), trans(values)

        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(
                    module.case_list.label) or "Case List"
                icon = module.case_list.icon_app_string(
                    lang, for_default=for_default)
                audio = module.case_list.audio_app_string(
                    lang, for_default=for_default)
                if icon:
                    yield id_strings.case_list_icon_locale(module), icon
                if audio:
                    yield id_strings.case_list_audio_locale(module), audio

        if module_offers_search(module):
            yield id_strings.case_search_locale(module), trans(
                module.search_config.command_label)
            # icon and audio not yet available
            for prop in module.search_config.properties:
                yield id_strings.search_property_locale(
                    module, prop.name), trans(prop.label)

        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(
                    module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)

            icon = form.icon_app_string(lang, for_default=for_default)
            audio = form.audio_app_string(lang, for_default=for_default)
            if icon:
                yield id_strings.form_icon_locale(form), icon
            if audio:
                yield id_strings.form_audio_locale(form), audio

        if hasattr(module, 'case_list_form') and module.case_list_form.form_id:
            yield (id_strings.case_list_form_locale(module),
                   trans(module.case_list_form.label) or "Create a new Case")
            icon = module.case_list_form.icon_app_string(
                lang, for_default=for_default)
            audio = module.case_list_form.audio_app_string(
                lang, for_default=for_default)
            if icon:
                yield id_strings.case_list_form_icon_locale(module), icon
            if audio:
                yield id_strings.case_list_form_audio_locale(module), audio
Exemplo n.º 15
0
def _create_custom_app_strings(app, lang):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            elif detail_type.startswith('referral'):
                label = trans(module.referral_label)
            elif detail_type in ('product_short', 'product_long'):
                label = ''
            else:
                label = None
            if label is not None:
                yield id_strings.detail_title_locale(module, detail_type), label

            for column in detail.get_columns():
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(module, detail_type, column, item.key_as_variable), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(module, detail_type, column, index), trans(item.values)
                    for property, values in column.graph_configuration.locale_specific_config.iteritems():
                        yield id_strings.graph_configuration(module, detail_type, column, property), trans(values)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(module, detail_type, tab), trans(tab.header)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))
        if hasattr(module, 'report_configs'):
            for config in module.report_configs:
                yield id_strings.report_command(config.report_id), trans(config.header)
                yield id_strings.report_name(config.report_id), config.report.title
                yield id_strings.report_menu(), 'Reports'
                yield id_strings.report_name_header(), 'Report Name'
                yield id_strings.report_description_header(), 'Report Description'
                for column in config.report.report_columns:
                    yield (
                        id_strings.report_column_header(config.report_id, column.column_id),
                        column.get_header(lang)
                    )

        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)

        if hasattr(module, 'case_list_form') and module.case_list_form.form_id:
            yield (
                id_strings.case_list_form_locale(module),
                trans(module.case_list_form.label) or "Create a new Case"
            )