Ejemplo n.º 1
0
    def _get_column_context(self, column):
        from corehq.apps.app_manager.detail_screen import get_column_generator
        default_lang = self.app.default_language if not self.build_profile_id \
            else self.app.build_profiles[self.build_profile_id].langs[0]
        if column.useXpathExpression:
            xpath_function = escape(column.field, {'"': '"'})
        else:
            xpath_function = escape(
                get_column_generator(self.app, self.module, self.detail,
                                     column).xpath_function, {'"': '"'})
        context = {
            "xpath_function":
            xpath_function,
            "locale_id":
            id_strings.detail_column_header_locale(
                self.module,
                self.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(default_lang, ""))
        }
        if column.enum and column.format != "enum" and column.format != "conditional-enum":
            raise SuiteError(
                'Expected case tile field "{}" to be an id mapping with keys {}.'
                .format(column.case_tile_field,
                        ", ".join(['"{}"'.format(i.key)
                                   for i in column.enum])))

        context['variables'] = ''
        if column.format == "enum" or column.format == 'conditional-enum':
            context["variables"] = self._get_enum_variables(column)
        return context
Ejemplo n.º 2
0
    def details(self):

        r = []
        from corehq.apps.app_manager.detail_screen import get_column_generator
        if not self.app.use_custom_suite:
            for module in self.modules:
                for detail_type, detail, enabled in module.get_details():
                    detail_column_infos = get_detail_column_infos(
                        detail,
                        include_sort=detail_type.endswith('short'),
                    )

                    if detail_column_infos and enabled:
                        d = Detail(
                            id=self.id_strings.detail(module, detail_type),
                            title=Text(locale_id=self.id_strings.detail_title_locale(module, detail_type))
                        )

                        for column_info in detail_column_infos:
                            fields = get_column_generator(
                                self.app, module, detail,
                                detail_type=detail_type, *column_info
                            ).fields
                            d.fields.extend(fields)

                        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
                            r.append(d)

        return r
Ejemplo n.º 3
0
    def _get_column_context(self, column):
        from corehq.apps.app_manager.detail_screen import get_column_generator
        default_lang = self.app.default_language if not self.build_profile_id \
            else self.app.build_profiles[self.build_profile_id].langs[0]
        if column.useXpathExpression:
            xpath_function = escape(column.field, {'"': '"'})
        else:
            xpath_function = escape(get_column_generator(
                self.app, self.module, self.detail, column).xpath_function,
                {'"': '"'})
        context = {
            "xpath_function": xpath_function,
            "locale_id": id_strings.detail_column_header_locale(
                self.module, self.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(default_lang, "")
            )
        }
        if column.enum and column.format != "enum" and column.format != "conditional-enum":
            raise SuiteError(
                'Expected case tile field "{}" to be an id mapping with keys {}.'.format(
                    column.case_tile_field,
                    ", ".join(['"{}"'.format(i.key) for i in column.enum])
                )
            )

        context['variables'] = ''
        if column.format == "enum" or column.format == 'conditional-enum':
            context["variables"] = self._get_enum_variables(column)
        return context
Ejemplo n.º 4
0
    def details(self):
        r = []
        from corehq.apps.app_manager.detail_screen import get_column_generator
        if not self.app.use_custom_suite:
            for module in self.modules:
                for detail in module.get_details():
                    detail_columns = detail.get_columns()

                    if detail_columns and detail.type in ('case_short', 'case_long'):
                        d = Detail(
                            id=self.id_strings.detail(module, detail),
                            title=Text(locale_id=self.id_strings.detail_title_locale(module, detail))
                        )

                        if detail.type == 'case_short':
                            detail_fields = [c.field for c in detail_columns]
                            sort_fields = [e.field for e in module.detail_sort_elements]
                            sort_only_fields = [field for field in sort_fields
                                                if field not in detail_fields]

                            from corehq.apps.app_manager.models import DetailColumn
                            for sort_field in sort_only_fields:
                                # set up a fake detailcolumn so we can
                                # add this field but not actually
                                # save it
                                dc = DetailColumn(
                                    model='case',
                                    field=sort_field,
                                    format='invisible',
                                )
                                detail.append_column(dc)

                            # need to add a default here so that it doesn't
                            # get persisted
                            if self.app.enable_multi_sort and \
                               len(module.detail_sort_elements) == 0:
                                from corehq.apps.app_manager.models import SortElement
                                try:
                                    se = SortElement()
                                    se.field = detail.columns[0].field
                                    se.type = 'string'
                                    se.direction = 'ascending'
                                    module.detail_sort_elements.append(se)
                                except Exception:
                                    pass

                        for column in detail.get_columns():
                            fields = get_column_generator(self.app, module, detail, column).fields
                            d.fields.extend(fields)

                        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
                            r.append(d)

        return r
Ejemplo n.º 5
0
 def details(self):
     r = []
     from corehq.apps.app_manager.detail_screen import get_column_generator
     if not self.app.use_custom_suite:
         for module in self.modules:
             for detail in module.get_details():
                 detail_columns = detail.get_columns()
                 if detail_columns and detail.type in ('case_short',
                                                       'case_long'):
                     d = Detail(
                         id=self.id_strings.detail(module, detail),
                         title=Text(
                             locale_id=self.id_strings.detail_title_locale(
                                 module, detail)))
                     for column in detail_columns:
                         fields = get_column_generator(
                             self.app, module, detail, column).fields
                         d.fields.extend(fields)
                     try:
                         d.fields[0].sort = 'default'
                     except IndexError:
                         pass
                     else:
                         # only yield the Detail if it has Fields
                         r.append(d)
     return r
Ejemplo n.º 6
0
    def _get_column_context(self, column):
        from corehq.apps.app_manager.detail_screen import get_column_generator

        context = {
            "xpath_function": escape(
                get_column_generator(self.app, self.module, self.detail, column).xpath_function, {'"': """}
            ),
            "locale_id": id_strings.detail_column_header_locale(self.module, self.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":
            context["enum_keys"] = self._get_enum_keys(column)
        return context
Ejemplo n.º 7
0
 def _get_column_context(self, column):
     from corehq.apps.app_manager.detail_screen import get_column_generator
     default_lang = self.app.default_language if not self.build_profile_id \
         else self.app.build_profiles[self.build_profile_id].langs[0]
     context = {
         "xpath_function": escape(get_column_generator(
             self.app, self.module, self.detail, column).xpath_function,
             {'"': '"'}),
         "locale_id": id_strings.detail_column_header_locale(
             self.module, self.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(default_lang, "")
         )
     }
     if column.format == "enum":
         context["enum_keys"] = self._get_enum_keys(column)
     return context
Ejemplo n.º 8
0
    def details(self):

        r = []
        from corehq.apps.app_manager.detail_screen import get_column_generator
        if not self.app.use_custom_suite:
            for module in self.modules:
                for detail_type, detail, enabled in module.get_details():
                    if enabled:
                        detail_column_infos = get_detail_column_infos(
                            detail,
                            include_sort=detail_type.endswith('short'),
                        )

                        if detail_column_infos:
                            d = Detail(
                                id=self.id_strings.detail(module, detail_type),
                                title=Text(
                                    locale_id=self.id_strings.
                                    detail_title_locale(module, detail_type)))

                            for column_info in detail_column_infos:
                                fields = get_column_generator(
                                    self.app,
                                    module,
                                    detail,
                                    detail_type=detail_type,
                                    *column_info).fields
                                d.fields.extend(fields)

                            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
                                r.append(d)

        return r
Ejemplo n.º 9
0
 def details(self):
     r = []
     from corehq.apps.app_manager.detail_screen import get_column_generator
     if not self.app.use_custom_suite:
         for module in self.modules:
             for detail in module.get_details():
                 detail_columns = detail.get_columns()
                 if detail_columns and detail.type in ('case_short', 'case_long'):
                     d = Detail(
                         id=self.id_strings.detail(module, detail),
                         title=Text(locale_id=self.id_strings.detail_title_locale(module, detail))
                     )
                     for column in detail_columns:
                         fields = get_column_generator(self.app, module, detail, column).fields
                         d.fields.extend(fields)
                     try:
                         d.fields[0].sort = 'default'
                     except IndexError:
                         pass
                     else:
                         # only yield the Detail if it has Fields
                         r.append(d)
     return r
Ejemplo n.º 10
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
Ejemplo n.º 11
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
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def build_detail(self, module, detail_type, detail, detail_column_infos,
                     tabs, id, title, start, end):
        """
        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)
        if tabs:
            tab_spans = detail.get_tab_spans()
            for tab in tabs:
                sub_detail = self.build_detail(
                    module,
                    detail_type,
                    detail,
                    detail_column_infos,
                    [],
                    None,
                    Text(locale_id=id_strings.detail_tab_title_locale(
                        module, detail_type, tab
                    )),
                    tab_spans[tab.id][0],
                    tab_spans[tab.id][1]
                )
                if sub_detail:
                    d.details.append(sub_detail)
            if len(d.details):
                return d
            else:
                return None

        # Base case (has no tabs)
        else:
            # Add lookup
            if detail.lookup_enabled and detail.lookup_action:
                d.lookup = Lookup(
                    name=detail.lookup_name or None,
                    action=detail.lookup_action,
                    image=detail.lookup_image or None,
                )
                d.lookup.extras = [Extra(**e) for e in detail.lookup_extras]
                d.lookup.responses = [Response(**r) for r in detail.lookup_responses]

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

            # Add fields
            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):
                    self._add_action_to_detail(d, 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