Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv12102/SQLObject
Modified Files:
DBConnection.py SQLObject.py
Log Message:
* Joins now take an orderBy argument, and use the class's _defaultOrder
if no argument is given.
* defaultOrder/orderBy takes python attribute names, not DB names.
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** DBConnection.py 6 May 2003 22:43:34 -0000 1.33
--- DBConnection.py 24 May 2003 21:17:17 -0000 1.34
***************
*** 189,194 ****
if order and ops.get('groupBy'):
q = "%s GROUP BY %s" % (q, ", ".join(clauseList(ops['groupBy'])))
! if order and ops.get('orderBy'):
! q = "%s ORDER BY %s" % (q, ", ".join(clauseList(ops['orderBy'])))
start = ops.get('start', 0)
--- 189,194 ----
if order and ops.get('groupBy'):
q = "%s GROUP BY %s" % (q, ", ".join(clauseList(ops['groupBy'])))
! if order and ops.get('dbOrderBy'):
! q = "%s ORDER BY %s" % (q, ", ".join(clauseList(ops['dbOrderBy'])))
start = ops.get('start', 0)
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** SQLObject.py 24 May 2003 20:53:36 -0000 1.37
--- SQLObject.py 24 May 2003 21:17:17 -0000 1.38
***************
*** 913,920 ****
class Join(object):
! def __init__(self, otherClass, joinColumn=None, joinMethodName=None):
self.otherClass = otherClass
self.joinColumn = joinColumn
self.joinMethodName = joinMethodName
def initCallingClass(self, callingClass):
--- 913,922 ----
class Join(object):
! def __init__(self, otherClass, joinColumn=None, joinMethodName=None,
! orderBy=NoDefault):
self.otherClass = otherClass
self.joinColumn = joinColumn
self.joinMethodName = joinMethodName
+ self.orderBy = orderBy
def initCallingClass(self, callingClass):
***************
*** 935,938 ****
--- 937,950 ----
return False
+ def _applyOrderBy(self, results, defaultSortClass):
+ if self.orderBy is NoDefault:
+ self.orderBy = defaultSortClass._defaultOrder
+ if self.orderBy is not None:
+ def sorter(a, b, attr=self.orderBy):
+ return cmp(getattr(a, attr),
+ getattr(b, attr))
+ results.sort(sorter)
+ return results
+
# This is a one-to-many
class MultipleJoin(Join):
***************
*** 966,970 ****
self.joinColumn,
inst.id)
! return [cls(id) for (id,) in ids]
# This is a many-to-many join, with an intermediary table
--- 978,982 ----
self.joinColumn,
inst.id)
! return self._applyOrderBy([cls(id) for (id,) in ids], cls)
# This is a many-to-many join, with an intermediary table
***************
*** 1000,1004 ****
self.joinColumn,
inst.id)
! return [cls(id) for (id,) in ids]
def remove(self, inst, other):
--- 1012,1016 ----
self.joinColumn,
inst.id)
! return self._applyOrderBy([cls(id) for (id,) in ids], cls)
def remove(self, inst, other):
***************
*** 1038,1041 ****
--- 1050,1056 ----
if self.ops.get('orderBy', NoDefault) is NoDefault:
self.ops['orderBy'] = sourceClass._defaultOrder
+ orderBy = self.ops['orderBy']
+ if orderBy is not None:
+ self.ops['dbOrderBy'] = sourceClass._style.pythonAttrToDBColumn(orderBy)
def clone(self, **newOps):
|