Пример #1
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
Пример #2
0
 def sort_node(self):
     node = super(ConditionalEnum, self).sort_node
     if node:
         variables = self.variables
         for key in variables:
             node.text.xpath.node.append(
                 sx.XpathVariable(name=key, locale_id=variables[key]).node)
     return node
Пример #3
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
Пример #4
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