コード例 #1
0
ファイル: detail_screen.py プロジェクト: tsinkala/commcare-hq
 def __init__(self, app, module, detail, column):
     from corehq.apps.app_manager.suite_xml import IdStrings
     self.app = app
     self.module = module
     self.detail = detail
     self.column = column
     self.id_strings = IdStrings()
コード例 #2
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

    id_strings = IdStrings()
    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 isinstance(module, Module):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case 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)
コード例 #3
0
ファイル: detail_screen.py プロジェクト: birdsarah/core-hq
 def __init__(self, app, module, detail, column):
     from corehq.apps.app_manager.suite_xml import IdStrings
     self.app = app
     self.module = module
     self.detail = detail
     self.column = column
     self.id_strings = IdStrings()
コード例 #4
0
ファイル: detail_screen.py プロジェクト: birdsarah/core-hq
class FormattedDetailColumn(object):

    header_width = None
    template_width = None
    template_form = None

    def __init__(self, app, module, detail, column):
        from corehq.apps.app_manager.suite_xml import IdStrings
        self.app = app
        self.module = module
        self.detail = detail
        self.column = column
        self.id_strings = IdStrings()

    @property
    def locale_id(self):
        return self.id_strings.detail_column_header_locale(self.module, self.detail, self.column)

    @property
    def header(self):
        header = sx.Header(
            text=sx.Text(locale_id=self.locale_id),
            width=self.header_width
        )
        return header

    variables = None

    @property
    def template(self):
        template = sx.Template(
            text=sx.Text(xpath_function=self.xpath_function),
            form=self.template_form,
            width=self.template_width,
        )
        if self.variables:
            for key, value in sorted(self.variables.items()):
                template.text.xpath.variables.node.append(
                    sx.XpathVariable(name=key, locale_id=value).node
                )

        return template

    @property
    def xpath(self):
        return self.column.xpath

    XPATH_FUNCTION = u"{xpath}"

    def evaluate_template(self, template):
        if template:
            return template.format(
                xpath=self.xpath,
                app=self.app,
                module=self.module,
                detail=self.detail,
                column=self.column
            )

    @property
    def xpath_function(self):
        return self.evaluate_template(self.XPATH_FUNCTION)

    @property
    def hidden_header(self):
        return sx.Header(
            text=sx.Text(),
            width=0,
        )

    @property
    def hidden_template(self):
        return sx.Template(
            text=sx.Text(xpath_function=self.sort_xpath_function),
            width=0,
        )

    SORT_XPATH_FUNCTION = None

    @property
    def sort_xpath_function(self):
        return self.evaluate_template(self.SORT_XPATH_FUNCTION)

    @property
    def fields(self):
        if self.sort_xpath_function and self.detail.display == 'short':
            yield sx.Field(
                header=self.header,
                template=self.hidden_template,
            )
            yield sx.Field(
                header=self.hidden_header,
                template=self.template,
            )
        else:
            yield sx.Field(
                header=self.header,
                template=self.template,
            )
コード例 #5
0
ファイル: detail_screen.py プロジェクト: tsinkala/commcare-hq
class FormattedDetailColumn(object):

    header_width = None
    template_width = None
    template_form = None

    def __init__(self, app, module, detail, column):
        from corehq.apps.app_manager.suite_xml import IdStrings
        self.app = app
        self.module = module
        self.detail = detail
        self.column = column
        self.id_strings = IdStrings()

    @property
    def locale_id(self):
        return self.id_strings.detail_column_header_locale(
            self.module, self.detail, self.column)

    @property
    def header(self):
        header = sx.Header(text=sx.Text(locale_id=self.locale_id),
                           width=self.header_width)
        return header

    variables = None

    @property
    def template(self):
        template = sx.Template(
            text=sx.Text(xpath_function=self.xpath_function),
            form=self.template_form,
            width=self.template_width,
        )
        if self.variables:
            for key, value in sorted(self.variables.items()):
                template.text.xpath.variables.node.append(
                    sx.XpathVariable(name=key, locale_id=value).node)

        return template

    @property
    def xpath(self):
        return self.column.xpath

    XPATH_FUNCTION = u"{xpath}"

    def evaluate_template(self, template):
        if template:
            return template.format(xpath=self.xpath,
                                   app=self.app,
                                   module=self.module,
                                   detail=self.detail,
                                   column=self.column)

    @property
    def xpath_function(self):
        return self.evaluate_template(self.XPATH_FUNCTION)

    @property
    def hidden_header(self):
        return sx.Header(
            text=sx.Text(),
            width=0,
        )

    @property
    def hidden_template(self):
        return sx.Template(
            text=sx.Text(xpath_function=self.sort_xpath_function),
            width=0,
        )

    SORT_XPATH_FUNCTION = None

    @property
    def sort_xpath_function(self):
        return self.evaluate_template(self.SORT_XPATH_FUNCTION)

    @property
    def fields(self):
        if self.sort_xpath_function and self.detail.display == 'short':
            yield sx.Field(
                header=self.header,
                template=self.hidden_template,
            )
            yield sx.Field(
                header=self.hidden_header,
                template=self.template,
            )
        else:
            yield sx.Field(
                header=self.header,
                template=self.template,
            )