Ticket #16759: 16759_cleaned_up_where_clone.diff

File 16759_cleaned_up_where_clone.diff, 3.4 KB (added by Alexander Schepanovski, 13 years ago)

cleaned up diffrent approach

  • django/db/models/sql/aggregates.py

     
    6969
    7070        self.field = tmp
    7171
     72    def clone(self):
     73        return self
     74
    7275    def relabel_aliases(self, change_map):
    7376        if isinstance(self.col, (list, tuple)):
    7477            self.col = (change_map.get(self.col[0], self.col[0]), self.col[1])
  • django/db/models/sql/where.py

     
    260260    def relabel_aliases(self, change_map, node=None):
    261261        return
    262262
     263    def clone(self):
     264        return self
     265
    263266class NothingNode(object):
    264267    """
    265268    A node that matches nothing.
     
    270273    def relabel_aliases(self, change_map, node=None):
    271274        return
    272275
     276    def clone(self):
     277        return self
     278
    273279class ExtraWhere(object):
    274280    def __init__(self, sqls, params):
    275281        self.sqls = sqls
     
    278284    def as_sql(self, qn=None, connection=None):
    279285        return " AND ".join(self.sqls), tuple(self.params or ())
    280286
     287    def clone(self):
     288        return self
     289
    281290class Constraint(object):
    282291    """
    283292    An object that can be passed to WhereNode.add() and knows how to
     
    342351    def relabel_aliases(self, change_map):
    343352        if self.alias in change_map:
    344353            self.alias = change_map[self.alias]
     354
     355    def clone(self):
     356        return Constraint(self.alias, self.col, self.field)
  • django/db/models/sql/query.py

     
    254254        obj.dupe_avoidance = self.dupe_avoidance.copy()
    255255        obj.select = self.select[:]
    256256        obj.tables = self.tables[:]
    257         obj.where = copy.deepcopy(self.where, memo=memo)
     257        obj.where = self.where.clone()
    258258        obj.where_class = self.where_class
    259259        if self.group_by is None:
    260260            obj.group_by = None
    261261        else:
    262262            obj.group_by = self.group_by[:]
    263         obj.having = copy.deepcopy(self.having, memo=memo)
     263        obj.having = self.having.clone()
    264264        obj.order_by = self.order_by[:]
    265265        obj.low_mark, obj.high_mark = self.low_mark, self.high_mark
    266266        obj.distinct = self.distinct
  • django/utils/tree.py

     
    4545        return obj
    4646    _new_instance = classmethod(_new_instance)
    4747
     48    def clone(self):
     49        clone = self.__class__._new_instance(
     50            children=[], connector=self.connector, negated=self.negated)
     51        for child in self.children:
     52            if isinstance(child, tuple):
     53                clone.children.append(
     54                    (child[0].clone(), child[1], child[2], child[3]))
     55            else:
     56                clone.children.append(child.clone())
     57        for parent in self.subtree_parents:
     58            clone.subtree_parents.append(parent.clone())
     59        return clone
     60
    4861    def __str__(self):
    4962        if self.negated:
    5063            return '(NOT (%s: %s))' % (self.connector, ', '.join([str(c) for c
Back to Top