Django

Code

Show
Ignore:
Timestamp:
07/04/08 15:16:22 (6 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7772-7808,7811-7814,7816-7823,7826-7829,7831-7833,7835 via svnmerge from trunk. Modified GeoWhereNode accordingly for changes in r7835.

Files:

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  
    2929        self.subtree_parents = [] 
    3030        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) 
    3147 
    3248    def __str__(self): 
     
    8399                self.children.append(node) 
    84100        else: 
    85             obj = Node(self.children, self.connector, self.negated) 
     101            obj = self._new_instance(self.children, self.connector, 
     102                    self.negated) 
    86103            self.connector = conn_type 
    87104            self.children = [obj, node] 
     
    97114        method is useful for implementing "not" arrangements. 
    98115        """ 
    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)] 
    100118        self.connector = self.default 
    101119 
     
    109127            self.connector = conn_type 
    110128        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)] 
    112131            self.connector = conn_type 
    113132            self.negated = False 
    114133 
    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)) 
    117136        self.connector = self.default 
    118137        self.negated = False 
     
    127146        """ 
    128147        obj = self.subtree_parents.pop() 
    129         node = Node(self.children, self.connector) 
     148        node = self.__class__(self.children, self.connector) 
    130149        self.connector = obj.connector 
    131150        self.negated = obj.negated