Exemple #1
0
def _get_advanced_module_view_context(app, module, lang=None):
    case_property_builder = _setup_case_property_builder(app)
    case_type = module.case_type
    form_options = _case_list_form_options(app, module, case_type, lang)
    return {
        'fixture_columns_by_type': _get_fixture_columns_by_type(app.domain),
        'details': _get_module_details_context(app, module,
                                               case_property_builder,
                                               case_type),
        'case_list_form_options': form_options,
        'case_list_form_not_allowed_reason': _case_list_form_not_allowed_reason(
            module),
        'valid_parent_modules': [
            parent_module for parent_module in app.modules
            if not getattr(parent_module, 'root_module_id', None)
        ],
        'child_module_enabled': True,
        'is_search_enabled': case_search_enabled_for_domain(app.domain),
        'search_properties': module.search_config.properties if module_offers_search(module) else [],
        'include_closed': module.search_config.include_closed if module_offers_search(module) else False,
        'default_properties': module.search_config.default_properties if module_offers_search(module) else [],
        'schedule_phases': [
            {
                'id': schedule.id,
                'anchor': schedule.anchor,
                'forms': [
                    form.schedule_form_id for form in schedule.get_forms()
                ],
            } for schedule in module.get_schedule_phases()
        ],
    }
Exemple #2
0
def _get_advanced_module_view_context(app, module, lang=None):
    case_property_builder = _setup_case_property_builder(app)
    case_type = module.case_type
    form_options = _case_list_form_options(app, module, case_type, lang)
    return {
        'fixture_columns_by_type': _get_fixture_columns_by_type(app.domain),
        'details': _get_module_details_context(app, module,
                                               case_property_builder,
                                               case_type),
        'case_list_form_options': form_options,
        'case_list_form_not_allowed_reason': _case_list_form_not_allowed_reason(
            module),
        'valid_parent_modules': [
            parent_module for parent_module in app.modules
            if not getattr(parent_module, 'root_module_id', None)
        ],
        'child_module_enabled': True,
        'is_search_enabled': case_search_enabled_for_domain(app.domain),
        'search_properties': module.search_config.properties if module_offers_search(module) else [],
        'include_closed': module.search_config.include_closed if module_offers_search(module) else False,
        'default_properties': module.search_config.default_properties if module_offers_search(module) else [],
        'schedule_phases': [
            {
                'id': schedule.id,
                'anchor': schedule.anchor,
                'forms': [
                    form.schedule_form_id for form in schedule.get_forms()
                ],
            } for schedule in module.get_schedule_phases()
        ],
    }
Exemple #3
0
def _get_basic_module_view_context(app, module, lang=None):
    case_property_builder = _setup_case_property_builder(app)
    case_type = module.case_type
    form_options = _case_list_form_options(app, module, case_type, lang)
    # http://manage.dimagi.com/default.asp?178635
    allow_with_parent_select = app.build_version >= '2.23' or not module.parent_select.active
    allow_case_list_form = _case_list_form_not_allowed_reason(
        module,
        AllowWithReason(allow_with_parent_select, AllowWithReason.PARENT_SELECT_ACTIVE)
    )
    return {
        'parent_modules': _get_parent_modules(app, module, case_property_builder, case_type),
        'fixture_columns_by_type': _get_fixture_columns_by_type(app.domain),
        'details': _get_module_details_context(app, module, case_property_builder, case_type),
        'case_list_form_options': form_options,
        'case_list_form_not_allowed_reason': allow_case_list_form,
        'valid_parent_modules': _get_valid_parent_modules(app, module),
        'child_module_enabled': (
            toggles.BASIC_CHILD_MODULE.enabled(app.domain) and module.doc_type != "ShadowModule"
        ),
        'is_search_enabled': case_search_enabled_for_domain(app.domain),
        'search_properties': module.search_config.properties if module_offers_search(module) else [],
        'include_closed': module.search_config.include_closed if module_offers_search(module) else False,
        'default_properties': module.search_config.default_properties if module_offers_search(module) else [],
    }
Exemple #4
0
def _get_basic_module_view_context(app, module, lang=None):
    case_property_builder = _setup_case_property_builder(app)
    case_type = module.case_type
    form_options = _case_list_form_options(app, module, case_type, lang)
    # http://manage.dimagi.com/default.asp?178635
    allow_with_parent_select = app.build_version >= '2.23' or not module.parent_select.active
    allow_case_list_form = _case_list_form_not_allowed_reason(
        module,
        AllowWithReason(allow_with_parent_select, AllowWithReason.PARENT_SELECT_ACTIVE)
    )
    return {
        'parent_modules': _get_parent_modules(app, module, case_property_builder, case_type),
        'fixture_columns_by_type': _get_fixture_columns_by_type(app.domain),
        'details': _get_module_details_context(app, module, case_property_builder, case_type),
        'case_list_form_options': form_options,
        'case_list_form_not_allowed_reason': allow_case_list_form,
        'valid_parent_modules': _get_valid_parent_modules(app, module),
        'child_module_enabled': (
            toggles.BASIC_CHILD_MODULE.enabled(app.domain) and module.doc_type != "ShadowModule"
        ),
        'is_search_enabled': case_search_enabled_for_domain(app.domain),
        'search_properties': module.search_config.properties if module_offers_search(module) else [],
        'include_closed': module.search_config.include_closed if module_offers_search(module) else False,
        'default_properties': module.search_config.default_properties if module_offers_search(module) else [],
    }
Exemple #5
0
def _get_shared_module_view_context(app,
                                    module,
                                    case_property_builder,
                                    lang=None):
    '''
    Get context items that are used by both basic and advanced modules.
    '''
    case_type = module.case_type
    return {
        'details':
        _get_module_details_context(app, module, case_property_builder,
                                    case_type),
        'case_list_form_options':
        _case_list_form_options(app, module, case_type, lang),
        'valid_parent_modules':
        _get_valid_parent_modules(app, module),
        'js_options': {
            'fixture_columns_by_type':
            _get_fixture_columns_by_type(app.domain),
            'is_search_enabled':
            case_search_enabled_for_domain(app.domain),
            'search_properties':
            module.search_config.properties
            if module_offers_search(module) else [],
            'include_closed':
            module.search_config.include_closed
            if module_offers_search(module) else False,
            'default_properties':
            module.search_config.default_properties
            if module_offers_search(module) else [],
            'search_button_display_condition':
            module.search_config.search_button_display_condition
            if module_offers_search(module) else "",
        }
    }
Exemple #6
0
 def get_module_contributions(self, module):
     if module_offers_search(module):
         return [
             RemoteRequestFactory(self.app.domain, self.app,
                                  module).build_remote_request()
         ]
     return []
Exemple #7
0
def _get_shared_module_view_context(app, module, case_property_builder, lang=None):
    '''
    Get context items that are used by both basic and advanced modules.
    '''
    case_type = module.case_type
    context = {
        'details': _get_module_details_context(app, module, case_property_builder, case_type),
        'case_list_form_options': _case_list_form_options(app, module, case_type, lang),
        'valid_parents_for_child_module': _get_valid_parents_for_child_module(app, module),
        'js_options': {
            'fixture_columns_by_type': _get_fixture_columns_by_type(app.domain),
            'is_search_enabled': case_search_enabled_for_domain(app.domain),
            'search_properties': module.search_config.properties if module_offers_search(module) else [],
            'include_closed': module.search_config.include_closed if module_offers_search(module) else False,
            'default_properties': module.search_config.default_properties if module_offers_search(module) else [],
            'search_button_display_condition':
                module.search_config.search_button_display_condition if module_offers_search(module) else "",
            'blacklisted_owner_ids_expression': (
                module.search_config.blacklisted_owner_ids_expression if module_offers_search(module) else ""),
        },
        'legacy_select2': True,
    }
    if toggles.CASE_DETAIL_PRINT.enabled(app.domain):
        slug = 'module_%s_detail_print' % module.unique_id
        print_template = module.case_details.long.print_template
        print_uploader = MultimediaHTMLUploadController(
            slug,
            reverse(
                ProcessDetailPrintTemplateUploadView.urlname,
                args=[app.domain, app.id, module.unique_id],
            )
        )
        if not print_template:
            print_template = {
                'path': 'jr://file/commcare/text/%s.html' % slug,
            }
        context.update({
            'print_uploader': print_uploader,
            'print_uploader_js': print_uploader.js_options,
            'print_ref': ApplicationMediaReference(
                print_template.get('path'),
                media_class=CommCareMultimedia,
            ).as_dict(),
            'print_media_info': print_template,
        })
    return context
Exemple #8
0
def _get_shared_module_view_context(app, module, case_property_builder, lang=None):
    '''
    Get context items that are used by both basic and advanced modules.
    '''
    case_type = module.case_type
    context = {
        'details': _get_module_details_context(app, module, case_property_builder, case_type),
        'case_list_form_options': _case_list_form_options(app, module, case_type, lang),
        'valid_parent_modules': _get_valid_parent_modules(app, module),
        'js_options': {
            'fixture_columns_by_type': _get_fixture_columns_by_type(app.domain),
            'is_search_enabled': case_search_enabled_for_domain(app.domain),
            'search_properties': module.search_config.properties if module_offers_search(module) else [],
            'include_closed': module.search_config.include_closed if module_offers_search(module) else False,
            'default_properties': module.search_config.default_properties if module_offers_search(module) else [],
            'search_button_display_condition':
                module.search_config.search_button_display_condition if module_offers_search(module) else "",
            'blacklisted_owner_ids_expression': (
                module.search_config.blacklisted_owner_ids_expression if module_offers_search(module) else ""),
        }
    }
    if toggles.CASE_DETAIL_PRINT.enabled(app.domain):
        slug = 'module_%s_detail_print' % module.unique_id
        print_template = module.case_details.long.print_template
        print_uploader = MultimediaHTMLUploadController(
            slug,
            reverse(
                ProcessDetailPrintTemplateUploadView.name,
                args=[app.domain, app.id, module.unique_id],
            )
        )
        if not print_template:
            print_template = {
                'path': 'jr://file/commcare/text/%s.html' % slug,
            }
        context.update({
            'print_uploader': print_uploader,
            'print_uploader_js': print_uploader.js_options,
            'print_ref': ApplicationMediaReference(
                print_template.get('path'),
                media_class=CommCareMultimedia,
            ).as_dict(),
            'print_media_info': print_template,
        })
    return context
Exemple #9
0
def get_module_search_command_rows(langs, module):
    if not module_offers_search(module):
        return []

    return [
        ('search_command_label', 'list')
        + tuple(module.search_config.command_label.get(lang, '') for lang in langs),
        ('search_again_label', 'list')
        + tuple(module.search_config.again_label.get(lang, '') for lang in langs),
    ]
Exemple #10
0
def get_module_search_command_rows(langs, module, domain):
    if not module_offers_search(
            module) or not toggles.USH_CASE_CLAIM_UPDATES.enabled(domain):
        return []

    return [
        ('search_command_label', 'list') + tuple(
            module.search_config.command_label.get(lang, '')
            for lang in langs),
        ('search_again_label', 'list') + tuple(
            module.search_config.again_label.get(lang, '') for lang in langs),
    ]
Exemple #11
0
def get_child_case_types(app, case_type):
    """
    Get child case types used by search detail tab nodesets in any modules
    that match the given case type and are configured for case search.

    Returns a set of case types
    """
    case_types = set()
    for module in app.get_modules():
        if module.case_type == case_type and module_offers_search(module):
            for tab in module.search_detail("long").tabs:
                if tab.has_nodeset and tab.nodeset_case_type:
                    case_types.add(tab.nodeset_case_type)

    return case_types
Exemple #12
0
 def update_suite(self, detail_section_elements):
     for module in self.modules:
         if module_offers_search(module) or module_uses_smart_links(module):
             self.suite.remote_requests.append(
                 RemoteRequestFactory(
                     self.suite, module,
                     detail_section_elements).build_remote_request())
         if module.session_endpoint_id:
             self.suite.remote_requests.extend(
                 self.get_endpoint_contributions(module, None,
                                                 module.session_endpoint_id,
                                                 detail_section_elements))
         for form in module.get_forms():
             if form.session_endpoint_id:
                 self.suite.remote_requests.extend(
                     self.get_endpoint_contributions(
                         module, form, form.session_endpoint_id,
                         detail_section_elements))
Exemple #13
0
def get_related_case_relationships(app, case_type):
    """
    Get unique case relationships used by search details in any modules that
    match the given case type and are configured for case search.

    Returns a set of paths, e.g. {"parent", "host", "parent/parent"}
    """
    paths = set()
    for module in app.get_modules():
        if module.case_type == case_type and module_offers_search(module):
            for column in module.search_detail(
                    "short").columns + module.search_detail("long").columns:
                if not column.useXpathExpression:
                    parts = column.field.split("/")
                    if len(parts) > 1:
                        parts.pop(
                        )  # keep only the relationship: "parent", "parent/parent", etc.
                        paths.add("/".join(parts))
    return paths
Exemple #14
0
    def build_detail(self, module, detail_type, detail, detail_column_infos, tabs=None, id=None,
                     title=None, nodeset=None, print_template=None, start=0, end=None, relevant=None):
        """
        Recursively builds the Detail object.
        (Details can contain other details for each of their tabs)
        """
        from corehq.apps.app_manager.detail_screen import get_column_generator
        d = Detail(id=id, title=title, nodeset=nodeset, print_template=print_template, relevant=relevant)
        self._add_custom_variables(detail, d)
        if tabs:
            tab_spans = detail.get_tab_spans()
            for tab in tabs:
                # relevant should be set to None even in case its ''
                tab_relevant = None
                if tab.relevant and toggles.DISPLAY_CONDITION_ON_TABS.enabled(module.get_app().domain):
                    tab_relevant = tab.relevant

                sub_detail = self.build_detail(
                    module,
                    detail_type,
                    detail,
                    detail_column_infos,
                    title=Text(locale_id=id_strings.detail_tab_title_locale(
                        module, detail_type, tab
                    )),
                    nodeset=tab.nodeset if tab.has_nodeset else None,
                    start=tab_spans[tab.id][0],
                    end=tab_spans[tab.id][1],
                    relevant=tab_relevant,
                )
                if sub_detail:
                    d.details.append(sub_detail)
            if len(d.details):
                helper = EntriesHelper(self.app)
                datums = helper.get_datum_meta_module(module)
                d.variables.extend([DetailVariable(name=datum.datum.id, function=datum.datum.value) for datum in datums])
                return d
            else:
                return None

        # Base case (has no tabs)
        else:
            # Add lookup
            if detail.lookup_enabled and detail.lookup_action:
                d.lookup = self._get_lookup_element(detail, module)

            # Add variables
            variables = list(
                schedule_detail_variables(module, detail, detail_column_infos)
            )
            if variables:
                d.variables.extend(variables)

            # Add fields
            if end is None:
                end = len(detail_column_infos)
            for column_info in detail_column_infos[start:end]:
                # column_info is an instance of DetailColumnInfo named tuple. It has the following properties:
                #   column_info.column: an instance of app_manager.models.DetailColumn
                #   column_info.sort_element: an instance of app_manager.models.SortElement
                #   column_info.order: an integer
                fields = get_column_generator(
                    self.app, module, detail, parent_tab_nodeset=nodeset,
                    detail_type=detail_type, *column_info
                ).fields
                for field in fields:
                    d.fields.append(field)

            # Add actions
            if detail_type.endswith('short') and not module.put_in_root:
                if module.case_list_form.form_id:
                    target_form = self.app.get_form(module.case_list_form.form_id)
                    if target_form.is_registration_form(module.case_type):
                        d.actions.append(self._get_reg_form_action(module))

                if module_offers_search(module) and "search" not in id:
                    # Add the search action only if this isn't a search detail
                    d.actions.append(self._get_case_search_action(module))

            try:
                if not self.app.enable_multi_sort:
                    d.fields[0].sort = 'default'
            except IndexError:
                pass
            else:
                # only yield the Detail if it has Fields
                return d
    def get_module_contributions(self, module):
        if module_offers_search(module):
            domain = self.app.domain

            details_helper = DetailsHelper(self.app)

            remote_request = RemoteRequest(
                post=RemoteRequestPost(
                    url=absolute_reverse('claim_case', args=[domain]),
                    relevant=module.search_config.relevant,
                    data=[
                        QueryData(
                            key='case_id',
                            ref=QuerySessionXPath('case_id').instance(),
                            # e.g. instance('querysession')/session/data/case_id
                        ),
                    ]),
                command=Command(
                    id=id_strings.search_command(module),
                    display=Display(text=Text(
                        locale_id=id_strings.case_search_locale(module)), ),
                ),
                instances=[
                    Instance(id=SESSION_INSTANCE, src='jr://instance/session'),
                    Instance(id='casedb', src='jr://instance/casedb'),
                ],
                session=RemoteRequestSession(
                    queries=[
                        RemoteRequestQuery(
                            url=absolute_reverse('remote_search',
                                                 args=[domain]),
                            storage_instance=RESULTS_INSTANCE,
                            data=[
                                QueryData(key='case_type',
                                          ref="'{}'".format(module.case_type)),
                            ],
                            prompts=[
                                QueryPrompt(
                                    key=p.name,
                                    display=Display(
                                        text=Text(locale_id=id_strings.
                                                  search_property_locale(
                                                      module, p.name)), ),
                                ) for p in module.search_config.properties
                            ])
                    ],
                    data=[
                        SessionDatum(
                            id='case_id',
                            nodeset=(CaseTypeXpath(module.case_type).case(
                                instance_name=RESULTS_INSTANCE).select(
                                    u'@status', u'open', quote=True)),
                            value='./@case_id',
                            detail_select=details_helper.get_detail_id_safe(
                                module, 'case_short'),
                            detail_confirm=details_helper.get_detail_id_safe(
                                module, 'case_long'),
                        )
                    ],
                ),
                stack=Stack(),
            )

            frame = CreateFrame()
            # Open first form in module
            frame.add_command(XPath.string(id_strings.menu_id(module)))
            frame.add_datum(
                StackDatum(id='case_id',
                           value=QuerySessionXPath('case_id').instance()))
            remote_request.stack.add_frame(frame)

            return [remote_request]
        return []
Exemple #16
0
    def build_detail(self,
                     module,
                     detail_type,
                     detail,
                     detail_column_infos,
                     tabs=None,
                     id=None,
                     title=None,
                     nodeset=None,
                     start=0,
                     end=None):
        """
        Recursively builds the Detail object.
        (Details can contain other details for each of their tabs)
        """
        from corehq.apps.app_manager.detail_screen import get_column_generator
        d = Detail(id=id, title=title, nodeset=nodeset)
        if tabs:
            tab_spans = detail.get_tab_spans()
            for tab in tabs:
                sub_detail = self.build_detail(
                    module,
                    detail_type,
                    detail,
                    detail_column_infos,
                    title=Text(locale_id=id_strings.detail_tab_title_locale(
                        module, detail_type, tab)),
                    nodeset=tab.nodeset if tab.has_nodeset else None,
                    start=tab_spans[tab.id][0],
                    end=tab_spans[tab.id][1])
                if sub_detail:
                    d.details.append(sub_detail)
            if len(d.details):
                helper = EntriesHelper(self.app)
                datums = helper.get_datum_meta_module(module)
                d.variables.extend([
                    DetailVariable(name=datum.datum.id,
                                   function=datum.datum.value)
                    for datum in datums
                ])
                return d
            else:
                return None

        # Base case (has no tabs)
        else:
            # Add lookup
            if detail.lookup_enabled and detail.lookup_action:
                d.lookup = self._get_lookup_element(detail, module)

            # Add variables
            variables = list(
                schedule_detail_variables(module, detail, detail_column_infos))
            if variables:
                d.variables.extend(variables)

            # Add fields
            if end is None:
                end = len(detail_column_infos)
            for column_info in detail_column_infos[start:end]:
                fields = get_column_generator(self.app,
                                              module,
                                              detail,
                                              detail_type=detail_type,
                                              *column_info).fields
                d.fields.extend(fields)

            # Add actions
            if module.case_list_form.form_id and detail_type.endswith('short')\
                    and not module.put_in_root:
                target_form = self.app.get_form(module.case_list_form.form_id)
                if target_form.is_registration_form(module.case_type):
                    d.actions.append(self._get_reg_form_action(module))
            if module_offers_search(module) and detail_type.endswith(
                    'short') and not module.put_in_root:
                d.actions.append(self._get_case_search_action(module))

            try:
                if not self.app.enable_multi_sort:
                    d.fields[0].sort = 'default'
            except IndexError:
                pass
            else:
                # only yield the Detail if it has Fields
                return d
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():
                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)

            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)
                    )

        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
Exemple #18
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 and app.build_version >= LooseVersion('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

    for id, value in id_strings.REGEX_DEFAULT_VALUES.items():
        yield id, value

    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():
            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', 'conditional-enum'):
                    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 six.iteritems(
                            column.graph_configuration.locale_specific_config):
                        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 six.iteritems(
                                item.locale_specific_config):
                            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)
        custom_icon_form, custom_icon_text = module.custom_icon_form_and_text_by_language(
            lang)
        if icon:
            yield id_strings.module_icon_locale(module), icon
        if audio:
            yield id_strings.module_audio_locale(module), audio
        if custom_icon_form and custom_icon_text:
            yield _get_custom_icon_app_locale_and_value(custom_icon_form,
                                                        custom_icon_text,
                                                        module=module)

        if hasattr(module, 'report_configs'):
            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 six.iteritems(
                        config.complete_graph_configs):
                    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 six.iteritems(
                            graph_config.locale_specific_config):
                        yield id_strings.mobile_ucr_configuration(
                            module, config.uuid, property), trans(values)
                    for index, item in enumerate(graph_config.series):
                        for property, values in six.iteritems(
                                item.locale_specific_config):
                            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)
            custom_icon_form, custom_icon_text = form.custom_icon_form_and_text_by_language(
                lang)
            if icon:
                yield id_strings.form_icon_locale(form), icon
            if audio:
                yield id_strings.form_audio_locale(form), audio
            if custom_icon_form and custom_icon_text:
                yield _get_custom_icon_app_locale_and_value(custom_icon_form,
                                                            custom_icon_text,
                                                            form=form)

        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
Exemple #19
0
 def get_module_contributions(self, module):
     if module_offers_search(module):
         return [RemoteRequestFactory(self.app.domain, self.app, module).build_remote_request()]
     return []
Exemple #20
0
    def build_detail(self, module, detail_type, detail, detail_column_infos,
                     tabs=None, id=None, title=None, nodeset=None, start=0, end=None):
        """
        Recursively builds the Detail object.
        (Details can contain other details for each of their tabs)
        """
        from corehq.apps.app_manager.detail_screen import get_column_generator
        d = Detail(id=id, title=title, nodeset=nodeset)
        self._add_custom_variables(detail, d)
        if tabs:
            tab_spans = detail.get_tab_spans()
            for tab in tabs:
                sub_detail = self.build_detail(
                    module,
                    detail_type,
                    detail,
                    detail_column_infos,
                    title=Text(locale_id=id_strings.detail_tab_title_locale(
                        module, detail_type, tab
                    )),
                    nodeset=tab.nodeset if tab.has_nodeset else None,
                    start=tab_spans[tab.id][0],
                    end=tab_spans[tab.id][1]
                )
                if sub_detail:
                    d.details.append(sub_detail)
            if len(d.details):
                helper = EntriesHelper(self.app)
                datums = helper.get_datum_meta_module(module)
                d.variables.extend([DetailVariable(name=datum.datum.id, function=datum.datum.value) for datum in datums])
                return d
            else:
                return None

        # Base case (has no tabs)
        else:
            # Add lookup
            if detail.lookup_enabled and detail.lookup_action:
                d.lookup = self._get_lookup_element(detail, module)

            # Add variables
            variables = list(
                schedule_detail_variables(module, detail, detail_column_infos)
            )
            if variables:
                d.variables.extend(variables)

            # Add fields
            if end is None:
                end = len(detail_column_infos)
            for column_info in detail_column_infos[start:end]:
                fields = get_column_generator(
                    self.app, module, detail,
                    detail_type=detail_type, *column_info
                ).fields
                d.fields.extend(fields)

            # Add actions
            if module.case_list_form.form_id and detail_type.endswith('short')\
                    and not module.put_in_root:
                target_form = self.app.get_form(module.case_list_form.form_id)
                if target_form.is_registration_form(module.case_type):
                    d.actions.append(self._get_reg_form_action(module))
            if module_offers_search(module) and detail_type.endswith('short') and not module.put_in_root:
                d.actions.append(self._get_case_search_action(module))

            try:
                if not self.app.enable_multi_sort:
                    d.fields[0].sort = 'default'
            except IndexError:
                pass
            else:
                # only yield the Detail if it has Fields
                return d
Exemple #21
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 and app.build_version >= LooseVersion('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

    for id, value in id_strings.REGEX_DEFAULT_VALUES.items():
        yield id, value

    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():
            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', 'conditional-enum'):
                    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 six.iteritems(column.graph_configuration.locale_specific_config):
                        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 six.iteritems(item.locale_specific_config):
                            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)
        custom_icon_form, custom_icon_text = module.custom_icon_form_and_text_by_language(lang)
        if icon:
            yield id_strings.module_icon_locale(module), icon
        if audio:
            yield id_strings.module_audio_locale(module), audio
        if custom_icon_form and custom_icon_text:
            yield _get_custom_icon_app_locale_and_value(custom_icon_form, custom_icon_text, module=module)

        if hasattr(module, 'report_configs'):
            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 six.iteritems(config.complete_graph_configs):
                    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 six.iteritems(graph_config.locale_specific_config):
                        yield id_strings.mobile_ucr_configuration(module, config.uuid, property), trans(values)
                    for index, item in enumerate(graph_config.series):
                        for property, values in six.iteritems(item.locale_specific_config):
                            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)
            custom_icon_form, custom_icon_text = form.custom_icon_form_and_text_by_language(lang)
            if icon:
                yield id_strings.form_icon_locale(form), icon
            if audio:
                yield id_strings.form_audio_locale(form), audio
            if custom_icon_form and custom_icon_text:
                yield _get_custom_icon_app_locale_and_value(custom_icon_form, custom_icon_text, form=form)

            for id, custom_assertion in enumerate(form.custom_assertions):
                yield id_strings.custom_assertion_locale(module, form, id), trans(custom_assertion.text)

        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
Exemple #22
0
    def build_detail(self,
                     module,
                     detail_type,
                     detail,
                     detail_column_infos,
                     tabs=None,
                     id=None,
                     title=None,
                     nodeset=None,
                     print_template=None,
                     start=0,
                     end=None,
                     relevant=None):
        """
        Recursively builds the Detail object.
        (Details can contain other details for each of their tabs)
        """
        from corehq.apps.app_manager.detail_screen import get_column_generator
        d = Detail(id=id,
                   title=title,
                   nodeset=nodeset,
                   print_template=print_template,
                   relevant=relevant)
        self._add_custom_variables(detail, d)
        if tabs:
            tab_spans = detail.get_tab_spans()
            for tab in tabs:
                # relevant should be set to None even in case its ''
                tab_relevant = None
                if tab.relevant and toggles.DISPLAY_CONDITION_ON_TABS.enabled(
                        module.get_app().domain):
                    tab_relevant = tab.relevant

                sub_detail = self.build_detail(
                    module,
                    detail_type,
                    detail,
                    detail_column_infos,
                    title=Text(locale_id=id_strings.detail_tab_title_locale(
                        module, detail_type, tab)),
                    nodeset=tab.nodeset if tab.has_nodeset else None,
                    start=tab_spans[tab.id][0],
                    end=tab_spans[tab.id][1],
                    relevant=tab_relevant,
                )
                if sub_detail:
                    d.details.append(sub_detail)
            if len(d.details):
                helper = EntriesHelper(self.app)
                datums = helper.get_datum_meta_module(module)
                d.variables.extend([
                    DetailVariable(name=datum.datum.id,
                                   function=datum.datum.value)
                    for datum in datums
                ])
                return d
            else:
                return None

        # Base case (has no tabs)
        else:
            # Add lookup
            if detail.lookup_enabled and detail.lookup_action:
                d.lookup = self._get_lookup_element(detail, module)

            # Add variables
            variables = list(
                schedule_detail_variables(module, detail, detail_column_infos))
            if variables:
                d.variables.extend(variables)

            # Add fields
            if end is None:
                end = len(detail_column_infos)
            for column_info in detail_column_infos[start:end]:
                # column_info is an instance of DetailColumnInfo named tuple. It has the following properties:
                #   column_info.column: an instance of app_manager.models.DetailColumn
                #   column_info.sort_element: an instance of app_manager.models.SortElement
                #   column_info.order: an integer
                fields = get_column_generator(self.app,
                                              module,
                                              detail,
                                              parent_tab_nodeset=nodeset,
                                              detail_type=detail_type,
                                              *column_info).fields
                for field in fields:
                    d.fields.append(field)

            # Add actions
            if detail_type.endswith('short') and not module.put_in_root:
                if module.case_list_form.form_id:
                    target_form = self.app.get_form(
                        module.case_list_form.form_id)
                    if target_form.is_registration_form(module.case_type):
                        d.actions.append(self._get_reg_form_action(module))

                if module_offers_search(module):
                    d.actions.append(
                        self._get_case_search_action(module,
                                                     in_search="search" in id))

            try:
                if not self.app.enable_multi_sort:
                    d.fields[0].sort = 'default'
            except IndexError:
                pass
            else:
                # only yield the Detail if it has Fields
                return d
    def get_module_contributions(self, module):
        if module_offers_search(module):
            domain = self.app.domain

            details_helper = DetailsHelper(self.app)

            sync_request = SyncRequest(
                post=SyncRequestPost(
                    url=absolute_reverse('claim_case', args=[domain]),
                    # Check whether the case to be claimed already exists in casedb:
                    # count(
                    #   instance('casedb')/casedb/case[@case_id=instance('querysession')/session/data/case_id]
                    # ) = 0
                    relevant=XPath.count(
                        CaseIDXPath(QuerySessionXPath('case_id').instance()).case()
                    ) + ' = 0',
                    data=[
                        QueryData(
                            key='case_id',
                            ref=QuerySessionXPath('case_id').instance(),
                            # e.g. instance('querysession')/session/data/case_id
                        ),
                    ]
                ),

                command=Command(
                    id=id_strings.search_command(module),
                    display=Display(
                        text=Text(locale_id=id_strings.case_search_locale(module)),
                    ),
                ),

                instances=[Instance(
                    id=SESSION_INSTANCE,
                    src='jr://instance/session'
                )],

                session=SyncRequestSession(
                    queries=[
                        SyncRequestQuery(
                            url=absolute_reverse('sync_search', args=[domain]),
                            storage_instance=RESULTS_INSTANCE,
                            data=[
                                QueryData(
                                    key='case_type',
                                    ref="'{}'".format(module.case_type)
                                ),
                            ],
                            prompts=[
                                QueryPrompt(
                                    key=p.name,
                                    display=Display(
                                        text=Text(locale_id=id_strings.search_property_locale(module, p.name)),
                                    ),
                                ) for p in module.search_config.properties
                            ]
                        )
                    ],
                    data=[SessionDatum(
                        id='case_id',
                        nodeset=(CaseTypeXpath(module.case_type)
                                 .case(instance_name=RESULTS_INSTANCE)
                                 .select(u'@status', u'open', quote=True)),
                        value='./@case_id',
                        detail_select=details_helper.get_detail_id_safe(module, 'case_short'),
                        detail_confirm=details_helper.get_detail_id_safe(module, 'case_long'),
                    )],
                ),

                stack=Stack(),
            )

            frame = PushFrame()
            # Open first form in module
            frame.add_command(XPath.string(id_strings.menu_id(module)))
            frame.add_datum(StackDatum(id=CALCULATED_DATA, value=XPath.string(MARK_AS_CLAIMED)))
            sync_request.stack.add_frame(frame)

            return [sync_request]
        return []