Exemplo n.º 1
0
    def build_case_tile_detail(self, module, detail, detail_type):
        """
        Return a Detail node from an apps.app_manager.models.Detail that is
        configured to use case tiles.

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

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

        cols_by_tile = {col.case_tile_field: col for col in detail.columns}
        for template_field in ["header", "top_left", "sex", "bottom_left", "date"]:
            column = cols_by_tile.get(template_field, None)
            if column is None:
                raise SuiteError(
                    'No column was mapped to the "{}" case tile field'.format(
                        template_field
                    )
                )
            template_args[template_field] = {
                "prop_name": get_column_xpath_generator(
                    self.app, module, detail, column
                ).xpath,
                "locale_id": id_strings.detail_column_header_locale(
                    module, detail_type, column,
                ),
                # Just using default language for now
                # The right thing to do would be to reference the app_strings.txt I think
                "prefix": escape(
                    column.header.get(self.app.default_language, "")
                )
            }
            if column.format == "enum":
                template_args[template_field]["enum_keys"] = {}
                for mapping in column.enum:
                    template_args[template_field]["enum_keys"][mapping.key] = \
                        id_strings.detail_column_enum_variable(
                            module, detail_type, column, mapping.key_as_variable
                        )
        # Populate the template
        detail_as_string = self._case_tile_template_string.format(**template_args)
        return load_xmlobject_from_string(detail_as_string, xmlclass=Detail)
Exemplo n.º 2
0
 def _get_column_context(self, column):
     from corehq.apps.app_manager.detail_screen import get_column_xpath_generator
     context = {
         "prop_name": get_column_xpath_generator(
             self.app, self.module, self.detail, column
         ).xpath,
         "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
Exemplo n.º 3
0
    def combine_and_interpolate_V2_filters(cls, columns, app, module, detail):
        """
        Return a single filter xpath generated by ANDing together the given
        componenets. Also replaces "."s with the corresponding xpath.
        The interpolation here is specific to v2 apps! use
        combine_and_interpolate_V1_filters for V1 apps.
        :param column_filters: A list of columns
        :param app:
        :param module:
        :param detail:
        :return:
        """
        interpolated_filters = []
        for column in columns:
            if column.format == "filter":
                # filters might have a "." in them like: . = "VT"
                # We need to replace these dots with the names of the
                # properties that they refer to.
                #
                # So, if we had a case property called "state", the filter
                # xpath would be converted to: state = "VT"

                # The string that will replace "."s
                replacer_xpath = get_column_xpath_generator(
                    app, module, detail, column
                ).xpath

                # The filter with "."s replaced
                interpolated_xpath = dot_interpolate(
                    column.filter_xpath, replacer_xpath
                )

                interpolated_filters.append(interpolated_xpath)

        combined_filter = ' and '.join(
            '(%s)' % f for f in interpolated_filters
        )

        return combined_filter
Exemplo n.º 4
0
    def combine_and_interpolate_V2_filters(cls, columns, app, module, detail):
        """
        Return a single filter xpath generated by ANDing together the given
        componenets. Also replaces "."s with the corresponding xpath.
        The interpolation here is specific to v2 apps! use
        combine_and_interpolate_V1_filters for V1 apps.
        :param column_filters: A list of columns
        :param app:
        :param module:
        :param detail:
        :return:
        """
        interpolated_filters = []
        for column in columns:
            if column.format == "filter":
                # filters might have a "." in them like: . = "VT"
                # We need to replace these dots with the names of the
                # properties that they refer to.
                #
                # So, if we had a case property called "state", the filter
                # xpath would be converted to: state = "VT"

                # The string that will replace "."s
                replacer_xpath = get_column_xpath_generator(
                    app, module, detail, column).xpath

                # The filter with "."s replaced
                interpolated_xpath = dot_interpolate(column.filter_xpath,
                                                     replacer_xpath)

                interpolated_filters.append(interpolated_xpath)

        combined_filter = ' and '.join('(%s)' % f
                                       for f in interpolated_filters)

        return combined_filter