Exemple #1
0
    def template(self):
        template = sx.GraphTemplate(
            form=self.template_form,
            graph=sx.Graph(
                type=self.column.graph_configuration.graph_type,
                series=[
                    sx.Series(
                        nodeset=s.data_path,
                        x_function=s.x_function,
                        y_function=s.y_function,
                        radius_function=s.radius_function,
                        configuration=sx.ConfigurationGroup(configs=([
                            # TODO: It might be worth wrapping
                            #       these values in quotes (as appropriate)
                            #       to prevent the user from having to
                            #       figure out why their unquoted colors
                            #       aren't working.
                            sx.ConfigurationItem(id=k, xpath_function=v)
                            for k, v in s.config.iteritems()
                        ] + [
                            sx.ConfigurationItem(
                                id=k,
                                locale_id=self.id_strings.
                                graph_series_configuration(
                                    self.module, self.detail_type, self.column,
                                    index, k))
                            for k, v in s.locale_specific_config.iteritems()
                        ]))) for index, s in enumerate(
                            self.column.graph_configuration.series)
                ],
                configuration=sx.ConfigurationGroup(configs=([
                    sx.ConfigurationItem(id=k, xpath_function=v) for k, v in
                    self.column.graph_configuration.config.iteritems()
                ] + [
                    sx.ConfigurationItem(
                        id=k,
                        locale_id=self.id_strings.graph_configuration(
                            self.module, self.detail_type, self.column, k))
                    for k, v in self.column.graph_configuration.
                    locale_specific_config.iteritems()
                ])),
                annotations=[
                    sx.Annotation(
                        x=sx.Text(xpath_function=a.x),
                        y=sx.Text(xpath_function=a.y),
                        text=sx.
                        Text(locale_id=self.id_strings.graph_annotation(
                            self.module, self.detail_type, self.column, i)))
                    for i, a in enumerate(
                        self.column.graph_configuration.annotations)
                ]))

        # TODO: what are self.variables and do I need to care about them here?
        # (see FormattedDetailColumn.template)

        return template
    def sort_node(self):
        if not (self.app.enable_multi_sort and
                (self.detail.display == 'short' or self.has_sort_node_for_nodeset_column())
                ):
            return

        sort = None

        if self.sort_xpath_function:
            if self.sort_element and self.sort_element.type == 'index':
                sort_type = self.sort_element.type
            else:
                sort_type = self.SORT_TYPE

            sort = sx.Sort(
                text=sx.Text(xpath_function=self.sort_xpath_function),
                type=sort_type,
            )

        if self.sort_element:
            if not sort:
                sort_type = {
                    'date': 'string',
                    'plain': 'string',
                    'distance': 'double'
                }.get(self.sort_element.type, self.sort_element.type)

                sort_calculation = self.sort_element.sort_calculation
                if sort_calculation:
                    sort_xpath = sort_calculation
                else:
                    sort_xpath = self.xpath_function

                sort = sx.Sort(
                    text=sx.Text(xpath_function=sort_xpath),
                    type=sort_type,
                )

            if self.sort_element.type == 'distance':
                sort.text.xpath_function = self.evaluate_template(Distance.SORT_XPATH_FUNCTION)

            sort.order = self.order
            sort.direction = self.sort_element.direction
            sort.blanks = self.sort_element.blanks

            # Flag field as index by making order "-2"
            # this is for the CACHE_AND_INDEX toggle
            # (I know, I know, it's hacky - blame Clayton)
            if sort.type == 'index':
                sort.type = 'string'
                sort.order = -2

        return sort
Exemple #3
0
 def header(self):
     if self.detail.display == 'short' or self.has_sort_node_for_nodeset_column(
     ):
         header = sx.Header(text=sx.Text(), width=self.template_width)
     else:
         header = super(HideShortHeaderColumn, self).header
     return header
Exemple #4
0
    def template(self):
        template = sx.Template(
            text=sx.Text(xpath_function=self.xpath_function),
            form=self.template_form,
            width=self.template_width,
        )

        if self.column.useXpathExpression:
            xpath = sx.CalculatedPropertyXpath(function=self.xpath)
            if re.search(r'\$lang', self.xpath):
                xpath.variables.node.append(
                    sx.CalculatedPropertyXpathVariable(
                        name=u'lang',
                        locale_id=self.id_strings.current_language()
                    ).node
                )
            xpath_variable = sx.XpathVariable(name=u'calculated_property', xpath=xpath)
            template.text.xpath.variables.node.append(xpath_variable.node)

        if self.variables:
            for key, value in sorted(self.variables.items()):
                template.text.xpath.variables.node.append(
                    sx.XpathVariable(name=key, locale_id=value).node
                )

        return template
Exemple #5
0
 def header(self):
     if self.detail.display == 'short':
         header = sx.Header(
             text=sx.Text(),
             width=self.template_width
         )
     else:
         header = super(HideShortHeaderColumn, self).header
     return header
Exemple #6
0
 def header(self):
     """
     header given for an invisible column to enable its display as a sort field in sort menu even
     when missing amongst display properties for case list headers
     refer: http://manage.dimagi.com/default.asp?232411
     """
     if self.sort_element and self.sort_element.has_display_values():
         header = sx.Header(text=sx.Text(locale_id=self.locale_id),
                            width=self.template_width)
     else:
         header = super(Invisible, self).header
     return header
Exemple #7
0
    def template(self):
        template = sx.Template(
            text=sx.Text(xpath_function=self.xpath_function),
            form=self.template_form,
            width=self.template_width,
        )
        if self.variables:
            for key, value in sorted(self.variables.items()):
                template.text.xpath.variables.node.append(
                    sx.XpathVariable(name=key, locale_id=value).node)

        return template
Exemple #8
0
 def hidden_template(self):
     return sx.Template(
         text=sx.Text(xpath_function=self.sort_xpath_function),
         width=0,
     )
Exemple #9
0
 def hidden_header(self):
     return sx.Header(
         text=sx.Text(),
         width=0,
     )
Exemple #10
0
    def sort_node(self):
        if not (self.app.enable_multi_sort and
                (self.detail.display == 'short'
                 or self.has_sort_node_for_nodeset_column())):
            return

        sort = None

        if self.sort_xpath_function:
            if self.sort_element and self.sort_element.type == 'index':
                sort_type = self.sort_element.type
            else:
                sort_type = self.SORT_TYPE

            sort = sx.Sort(
                text=sx.Text(xpath_function=self.sort_xpath_function),
                type=sort_type,
            )

            if self.column.useXpathExpression:
                xpath = sx.CalculatedPropertyXpath(function=self.xpath)
                if re.search(r'\$lang', self.xpath):
                    xpath.variables.node.append(
                        sx.CalculatedPropertyXpathVariable(
                            name='lang',
                            locale_id=self.id_strings.current_language()).node)
                xpath_variable = sx.XpathVariable(name='calculated_property',
                                                  xpath=xpath)
                sort.text.xpath.variables.node.append(xpath_variable.node)

        if self.sort_element:
            if not sort:
                sort_type = {
                    'date': 'string',
                    'plain': 'string',
                    'distance': 'double'
                }.get(self.sort_element.type, self.sort_element.type)

                sort_calculation = self.sort_element.sort_calculation
                if sort_calculation:
                    sort_xpath = sort_calculation
                else:
                    sort_xpath = self.xpath_function

                sort = sx.Sort(
                    text=sx.Text(xpath_function=sort_xpath),
                    type=sort_type,
                )
                if not sort_calculation and self.column.useXpathExpression:
                    xpath = sx.CalculatedPropertyXpath(function=self.xpath)
                    if re.search(r'\$lang', self.xpath):
                        xpath.variables.node.append(
                            sx.CalculatedPropertyXpathVariable(
                                name='lang',
                                locale_id=self.id_strings.current_language()).
                            node)
                    xpath_variable = sx.XpathVariable(
                        name='calculated_property', xpath=xpath)
                    sort.text.xpath.variables.node.append(xpath_variable.node)

            if self.sort_element.type == 'distance':
                sort.text.xpath_function = self.evaluate_template(
                    Distance.SORT_XPATH_FUNCTION)

            sort.order = self.order
            sort.direction = self.sort_element.direction
            sort.blanks = self.sort_element.blanks

            # Flag field as index by making order "-2"
            # this is for the CACHE_AND_INDEX toggle
            # (I know, I know, it's hacky - blame Clayton)
            if sort.type == 'index':
                sort.type = 'string'
                sort.order = -2

        return sort
Exemple #11
0
 def header(self):
     header = sx.Header(text=sx.Text(locale_id=self.locale_id),
                        width=self.header_width)
     return header