当前位置: 首页>>代码示例>>Python>>正文


Python tree.Node方法代码示例

本文整理汇总了Python中django.utils.tree.Node方法的典型用法代码示例。如果您正苦于以下问题:Python tree.Node方法的具体用法?Python tree.Node怎么用?Python tree.Node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.tree的用法示例。


在下文中一共展示了tree.Node方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_filtered_relation_q

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def build_filtered_relation_q(self, q_object, reuse, branch_negated=False, current_negated=False):
        """Add a FilteredRelation object to the current filter."""
        connector = q_object.connector
        current_negated ^= q_object.negated
        branch_negated = branch_negated or q_object.negated
        target_clause = self.where_class(connector=connector, negated=q_object.negated)
        for child in q_object.children:
            if isinstance(child, Node):
                child_clause = self.build_filtered_relation_q(
                    child, reuse=reuse, branch_negated=branch_negated,
                    current_negated=current_negated,
                )
            else:
                child_clause, _ = self.build_filter(
                    child, can_reuse=reuse, branch_negated=branch_negated,
                    current_negated=current_negated,
                    allow_joins=True, split_subq=False,
                    reuse_with_filtered_relation=True,
                )
            target_clause.add(child_clause, connector)
        return target_clause 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:23,代码来源:query.py

示例2: relabel_aliases

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def relabel_aliases(self, change_map, node=None):
        """
        Relabels the alias values of any children. 'change_map' is a dictionary
        mapping old (current) alias values to the new values.
        """
        if not node:
            node = self
        for pos, child in enumerate(node.children):
            if hasattr(child, 'relabel_aliases'):
                child.relabel_aliases(change_map)
            elif isinstance(child, tree.Node):
                self.relabel_aliases(change_map, child)
            elif isinstance(child, (list, tuple)):
                if isinstance(child[0], (list, tuple)):
                    elt = list(child[0])
                    if elt[0] in change_map:
                        elt[0] = change_map[elt[0]]
                        node.children[pos] = (tuple(elt),) + child[1:]
                else:
                    child[0].relabel_aliases(change_map)

                # Check if the query value also requires relabelling
                if hasattr(child[3], 'relabel_aliases'):
                    child[3].relabel_aliases(change_map) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:26,代码来源:where.py

示例3: _refs_aggregate

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def _refs_aggregate(cls, obj, existing_aggregates):
        if not isinstance(obj, tree.Node):
            aggregate, aggregate_lookups = refs_aggregate(obj[0].split(LOOKUP_SEP), existing_aggregates)
            if not aggregate and hasattr(obj[1], 'refs_aggregate'):
                return obj[1].refs_aggregate(existing_aggregates)
            return aggregate, aggregate_lookups
        for c in obj.children:
            aggregate, aggregate_lookups = cls._refs_aggregate(c, existing_aggregates)
            if aggregate:
                return aggregate, aggregate_lookups
        return False, () 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:query_utils.py

示例4: _contains_aggregate

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def _contains_aggregate(cls, obj):
        if not isinstance(obj, tree.Node):
            return getattr(obj.lhs, 'contains_aggregate', False) or getattr(obj.rhs, 'contains_aggregate', False)
        return any(cls._contains_aggregate(c) for c in obj.children) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:where.py

示例5: split_having_parts

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def split_having_parts(self, q_object, negated=False):
        """
        Returns a list of q_objects which need to go into the having clause
        instead of the where clause. Removes the splitted out nodes from the
        given q_object. Note that the q_object is altered, so cloning it is
        needed.
        """
        having_parts = []
        for c in q_object.children[:]:
            # When constructing the having nodes we need to take care to
            # preserve the negation status from the upper parts of the tree
            if isinstance(c, Node):
                # For each negated child, flip the in_negated flag.
                in_negated = c.negated ^ negated
                if c.connector == OR and self.need_having(c):
                    # A subtree starting from OR clause must go into having in
                    # whole if any part of that tree references an aggregate.
                    q_object.children.remove(c)
                    having_parts.append(c)
                    c.negated = in_negated
                else:
                    having_parts.extend(
                        self.split_having_parts(c, in_negated)[1])
            elif self.need_having(c):
                q_object.children.remove(c)
                new_q = self.where_class(children=[c], negated=negated)
                having_parts.append(new_q)
        return q_object, having_parts 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:30,代码来源:query.py

示例6: _add_q

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def _add_q(self, q_object, used_aliases, branch_negated=False,
               current_negated=False, allow_joins=True, split_subq=True):
        """
        Adds a Q-object to the current filter.
        """
        connector = q_object.connector
        current_negated = current_negated ^ q_object.negated
        branch_negated = branch_negated or q_object.negated
        target_clause = self.where_class(connector=connector,
                                         negated=q_object.negated)
        joinpromoter = JoinPromoter(q_object.connector, len(q_object.children), current_negated)
        for child in q_object.children:
            if isinstance(child, Node):
                child_clause, needed_inner = self._add_q(
                    child, used_aliases, branch_negated,
                    current_negated, allow_joins, split_subq)
                joinpromoter.add_votes(needed_inner)
            else:
                child_clause, needed_inner = self.build_filter(
                    child, can_reuse=used_aliases, branch_negated=branch_negated,
                    current_negated=current_negated, connector=connector,
                    allow_joins=allow_joins, split_subq=split_subq,
                )
                joinpromoter.add_votes(needed_inner)
            target_clause.add(child_clause, connector)
        needed_inner = joinpromoter.update_join_types(self)
        return target_clause, needed_inner 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:29,代码来源:query.py

示例7: _contains_aggregate

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def _contains_aggregate(cls, obj):
        if isinstance(obj, tree.Node):
            return any(cls._contains_aggregate(c) for c in obj.children)
        return obj.contains_aggregate 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:6,代码来源:where.py

示例8: _contains_over_clause

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def _contains_over_clause(cls, obj):
        if isinstance(obj, tree.Node):
            return any(cls._contains_over_clause(c) for c in obj.children)
        return obj.contains_over_clause 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:6,代码来源:where.py

示例9: get_children_from_q

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def get_children_from_q(q):
    for child in q.children:
        if isinstance(child, Node):
            yield from get_children_from_q(child)
        else:
            yield child 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:8,代码来源:query.py

示例10: _add_q

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def _add_q(self, q_object, used_aliases, branch_negated=False,
               current_negated=False, allow_joins=True, split_subq=True):
        """Add a Q-object to the current filter."""
        connector = q_object.connector
        current_negated = current_negated ^ q_object.negated
        branch_negated = branch_negated or q_object.negated
        target_clause = self.where_class(connector=connector,
                                         negated=q_object.negated)
        joinpromoter = JoinPromoter(q_object.connector, len(q_object.children), current_negated)
        for child in q_object.children:
            if isinstance(child, Node):
                child_clause, needed_inner = self._add_q(
                    child, used_aliases, branch_negated,
                    current_negated, allow_joins, split_subq)
                joinpromoter.add_votes(needed_inner)
            else:
                child_clause, needed_inner = self.build_filter(
                    child, can_reuse=used_aliases, branch_negated=branch_negated,
                    current_negated=current_negated, allow_joins=allow_joins,
                    split_subq=split_subq,
                )
                joinpromoter.add_votes(needed_inner)
            if child_clause:
                target_clause.add(child_clause, connector)
        needed_inner = joinpromoter.update_join_types(self)
        return target_clause, needed_inner 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:28,代码来源:query.py

示例11: _add_q

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def _add_q(self, q_object, used_aliases, branch_negated=False,
               current_negated=False, allow_joins=True, split_subq=True):
        """
        Adds a Q-object to the current filter.
        """
        connector = q_object.connector
        current_negated = current_negated ^ q_object.negated
        branch_negated = branch_negated or q_object.negated
        target_clause = self.where_class(connector=connector,
                                         negated=q_object.negated)
        joinpromoter = JoinPromoter(q_object.connector, len(q_object.children), current_negated)
        for child in q_object.children:
            if isinstance(child, Node):
                child_clause, needed_inner = self._add_q(
                    child, used_aliases, branch_negated,
                    current_negated, allow_joins, split_subq)
                joinpromoter.add_votes(needed_inner)
            else:
                child_clause, needed_inner = self.build_filter(
                    child, can_reuse=used_aliases, branch_negated=branch_negated,
                    current_negated=current_negated, connector=connector,
                    allow_joins=allow_joins, split_subq=split_subq,
                )
                joinpromoter.add_votes(needed_inner)
            if child_clause:
                target_clause.add(child_clause, connector)
        needed_inner = joinpromoter.update_join_types(self)
        return target_clause, needed_inner 
开发者ID:Yeah-Kun,项目名称:python,代码行数:30,代码来源:query.py

示例12: need_force_having

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def need_force_having(self, q_object):
        """
        Returns whether or not all elements of this q_object need to be put
        together in the HAVING clause.
        """
        for child in q_object.children:
            if isinstance(child, Node):
                if self.need_force_having(child):
                    return True
            else:
                if child[0].split(LOOKUP_SEP)[0] in self.aggregates:
                    return True
        return False 
开发者ID:blackye,项目名称:luscan-devel,代码行数:15,代码来源:query.py

示例13: add_q

# 需要导入模块: from django.utils import tree [as 别名]
# 或者: from django.utils.tree import Node [as 别名]
def add_q(self, q_object, used_aliases=None, force_having=False):
        """
        Adds a Q-object to the current filter.

        Can also be used to add anything that has an 'add_to_query()' method.
        """
        if used_aliases is None:
            used_aliases = self.used_aliases
        if hasattr(q_object, 'add_to_query'):
            # Complex custom objects are responsible for adding themselves.
            q_object.add_to_query(self, used_aliases)
        else:
            if self.where and q_object.connector != AND and len(q_object) > 1:
                self.where.start_subtree(AND)
                subtree = True
            else:
                subtree = False
            connector = AND
            if q_object.connector == OR and not force_having:
                force_having = self.need_force_having(q_object)
            for child in q_object.children:
                if connector == OR:
                    refcounts_before = self.alias_refcount.copy()
                if force_having:
                    self.having.start_subtree(connector)
                else:
                    self.where.start_subtree(connector)
                if isinstance(child, Node):
                    self.add_q(child, used_aliases, force_having=force_having)
                else:
                    self.add_filter(child, connector, q_object.negated,
                            can_reuse=used_aliases, force_having=force_having)
                if force_having:
                    self.having.end_subtree()
                else:
                    self.where.end_subtree()

                if connector == OR:
                    # Aliases that were newly added or not used at all need to
                    # be promoted to outer joins if they are nullable relations.
                    # (they shouldn't turn the whole conditional into the empty
                    # set just because they don't match anything).
                    self.promote_unused_aliases(refcounts_before, used_aliases)
                connector = q_object.connector
            if q_object.negated:
                self.where.negate()
            if subtree:
                self.where.end_subtree()
        if self.filter_is_sticky:
            self.used_aliases = used_aliases 
开发者ID:blackye,项目名称:luscan-devel,代码行数:52,代码来源:query.py


注:本文中的django.utils.tree.Node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。