Changeset 7836 for django/branches/gis/django/utils/tree.py
- Timestamp:
- 07/04/08 15:16:22 (6 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/utils/tree.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7767 to /django/trunk:1-7835
django/branches/gis/django/utils/tree.py
r7482 r7836 29 29 self.subtree_parents = [] 30 30 self.negated = negated 31 32 # We need this because of django.db.models.query_utils.Q. Q. __init__() is 33 # problematic, but it is a natural Node subclass in all other respects. 34 def _new_instance(cls, children=None, connector=None, negated=False): 35 """ 36 This is called to create a new instance of this class when we need new 37 Nodes (or subclasses) in the internal code in this class. Normally, it 38 just shadows __init__(). However, subclasses with an __init__ signature 39 that is not an extension of Node.__init__ might need to implement this 40 method to allow a Node to create a new instance of them (if they have 41 any extra setting up to do). 42 """ 43 obj = Node(children, connector, negated) 44 obj.__class__ = cls 45 return obj 46 _new_instance = classmethod(_new_instance) 31 47 32 48 def __str__(self): … … 83 99 self.children.append(node) 84 100 else: 85 obj = Node(self.children, self.connector, self.negated) 101 obj = self._new_instance(self.children, self.connector, 102 self.negated) 86 103 self.connector = conn_type 87 104 self.children = [obj, node] … … 97 114 method is useful for implementing "not" arrangements. 98 115 """ 99 self.children = [Node(self.children, self.connector, not self.negated)] 116 self.children = [self._new_instance(self.children, self.connector, 117 not self.negated)] 100 118 self.connector = self.default 101 119 … … 109 127 self.connector = conn_type 110 128 elif self.connector != conn_type: 111 self.children = [Node(self.children, self.connector, self.negated)] 129 self.children = [self._new_instance(self.children, self.connector, 130 self.negated)] 112 131 self.connector = conn_type 113 132 self.negated = False 114 133 115 self.subtree_parents.append( Node(self.children, self.connector,116 self. negated))134 self.subtree_parents.append(self.__class__(self.children, 135 self.connector, self.negated)) 117 136 self.connector = self.default 118 137 self.negated = False … … 127 146 """ 128 147 obj = self.subtree_parents.pop() 129 node = Node(self.children, self.connector)148 node = self.__class__(self.children, self.connector) 130 149 self.connector = obj.connector 131 150 self.negated = obj.negated
