Changeset 3209
- Timestamp:
- 06/23/07 10:22:52 (2 years ago)
- Files:
-
- trunk/dabo/biz/dBizobj.py (modified) (38 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/biz/dBizobj.py
r3201 r3209 92 92 93 93 def setConnection(self, conn): 94 """Normally connections are established before bizobj creation, but 95 for those cases where connections are created later, use this method to 94 """Normally connections are established before bizobj creation, but 95 for those cases where connections are created later, use this method to 96 96 establish the connection used by the bizobj. 97 97 """ … … 119 119 crs.setCursorFactory(cf.getCursor, cursorClass) 120 120 return crs 121 121 122 122 123 123 def createCursor(self, key=None): … … 267 267 # Tell the cursor to begin a transaction, if needed. 268 268 cursor.beginTransaction() 269 269 270 270 try: 271 271 self.scanChangedRows(self.save, includeNewUnchanged=self.SaveNewUnchanged, … … 342 342 343 343 except dException.ConnectionLostException, e: 344 raise 344 raise 345 345 346 346 except dException.NoRecordsException, e: … … 390 390 raise dException.BusinessRuleViolation, errMsg 391 391 if ignoreNoRecords is None: 392 # Canceling changes when there are no records should 392 # Canceling changes when there are no records should 393 393 # normally not be a problem. 394 394 ignoreNoRecords = True … … 398 398 child.cancelAll(ignoreNoRecords=ignoreNoRecords) 399 399 self.afterCancel() 400 401 400 401 402 402 def deleteAllChildren(self, startTransaction=False): 403 403 """Delete all children associated with the current record without … … 464 464 child.cancelAll() 465 465 child.requery() 466 466 467 467 if startTransaction: 468 468 cursor.commitTransaction() 469 470 # Some backends (Firebird particularly) need to be told to write 469 470 # Some backends (Firebird particularly) need to be told to write 471 471 # their changes even if no explicit transaction was started. 472 472 cursor.flush() 473 473 474 474 self.afterPointerMove() 475 475 self.afterChange() … … 507 507 508 508 def getChangedRows(self, includeNewUnchanged=False): 509 """ Returns a list of row numbers for which isChanged() returns True. The 510 changes may therefore not be in the record itself, but in a dependent child 509 """ Returns a list of row numbers for which isChanged() returns True. The 510 changes may therefore not be in the record itself, but in a dependent child 511 511 record. If includeNewUnchanged is True, the presence of a new unsaved 512 512 record that has not been modified from its defaults will suffice to mark the … … 550 550 """ 551 551 return _bizIterator(self) 552 553 552 553 554 554 def scan(self, func, *args, **kwargs): 555 555 """Iterate over all records and apply the passed function to each. … … 558 558 559 559 If self.ScanRestorePosition is True, the position of the current 560 record in the recordset is restored after the iteration. If 560 record in the recordset is restored after the iteration. If 561 561 self.ScanReverse is True, the records are processed in reverse order. 562 562 """ … … 593 593 if row >= 0: 594 594 self.RowNumber = row 595 595 596 596 try: 597 597 if self.ScanReverse: … … 606 606 raise 607 607 restorePosition() 608 608 609 609 610 610 def scanChangedRows(self, func, allCursors=False, includeNewUnchanged=False, … … 612 612 """Move the record pointer to each changed row, and call func. 613 613 614 If allCursors is True, all other cursors for different parent records will 614 If allCursors is True, all other cursors for different parent records will 615 615 be iterated as well. 616 616 617 617 If includeNewUnchanged is True, new unsaved records that have not been 618 618 edited from their default values will be counted as 'changed'. … … 649 649 self._positionUsingPK(old_pk) 650 650 raise 651 651 652 652 self._CurrentCursor = old_currentCursorKey 653 653 if old_pk is not None: … … 761 761 # we still need to pass the exception to the UI 762 762 uiException = dException.NoRecordsException 763 763 764 764 except dException.dException, e: 765 765 # Something failed; reset things. … … 974 974 # No cursor, no changes. 975 975 return False 976 976 977 977 if cc.isChanged(allRows=True, includeNewUnchanged=self.SaveNewUnchanged): 978 978 return True 979 979 980 980 # Nothing's changed in the top level, so we need to recurse the children: 981 981 try: … … 984 984 # If there are no records, there can be no changes 985 985 return False 986 986 987 987 for child in self.__children: 988 988 if child.isAnyChanged(parentPK=pk): … … 1073 1073 1074 1074 def onNew(self): 1075 """Called when a new record is added. 1076 1077 Use this hook to add additional default field values, or anything else 1075 """Called when a new record is added. 1076 1077 Use this hook to add additional default field values, or anything else 1078 1078 you need. If you change field values here, the memento system will not 1079 1079 catch it (the record will not be marked 'dirty'). Use afterNew() if you … … 1223 1223 1224 1224 def getParentPK(self): 1225 """ Return the value of the parent bizobjs' PK field. 1226 1227 Alternatively, user code can just call self.Parent.getPK(). 1225 """ Return the value of the parent bizobjs' PK field. Alternatively, 1226 user code can just call self.Parent.getPK(). 1228 1227 """ 1229 1228 try: … … 1249 1248 except dException.NoRecordsException: 1250 1249 ret = False 1251 return ret 1250 return ret 1252 1251 1253 1252 … … 1424 1423 def beforeCreateCursor(self): return "" 1425 1424 ########## Post-hook interface section ############## 1426 def afterNew(self): 1427 """Called after a new record is added. 1425 def afterNew(self): 1426 """Called after a new record is added. 1428 1427 1429 1428 Use this hook to change field values, or anything else you need. If you … … 1453 1452 1454 1453 def _setAutoCommit(self, val): 1455 self._CurrentCursor.AutoCommit = val 1454 for crs in self.__cursors.values(): 1455 crs.AutoCommit = val 1456 1456 1457 1457 … … 1464 1464 def _setAutoPopulatePK(self, val): 1465 1465 self._autoPopulatePK = bool(val) 1466 if self._CurrentCursor:1467 self._CurrentCursor.AutoPopulatePK = val1466 for crs in self.__cursors.values(): 1467 crs.AutoPopulatePK = val 1468 1468 1469 1469 … … 1473 1473 def _setAutoQuoteNames(self, val): 1474 1474 self._autoQuoteNames = val 1475 if self._CurrentCursor:1476 self._CurrentCursor.AutoQuoteNames = val1475 for crs in self.__cursors.values(): 1476 crs.AutoQuoteNames = val 1477 1477 1478 1478 … … 1526 1526 def _setDataSource(self, val): 1527 1527 self._dataSource = str(val) 1528 cursor = self._CurrentCursor 1529 if cursor is not None: 1530 cursor.Table = val 1528 for crs in self.__cursors.values(): 1529 crs.Table = val 1531 1530 1532 1531 … … 1560 1559 1561 1560 def _setVirtualFields(self, val): 1562 for key, cursor in self.__cursors.items():1563 c ursor.VirtualFields = val1561 for crs in self.__cursors.values(): 1562 crs.VirtualFields = val 1564 1563 self._virtualFields = val 1565 1564 … … 1578 1577 1579 1578 def _setEncoding(self, val): 1580 cursor = self._CurrentCursor 1581 if cursor is not None: 1582 cursor.Encoding = val 1579 for crs in self.__cursors.values(): 1580 crs.Encoding = val 1583 1581 1584 1582 … … 1605 1603 def _setKeyField(self, val): 1606 1604 self._keyField = val 1607 cursor = self._CurrentCursor 1608 if cursor is not None: 1609 cursor.KeyField = val 1605 for crs in self.__cursors.values(): 1606 crs.KeyField = val 1610 1607 1611 1608 … … 1654 1651 if fldList is None: 1655 1652 fldList = [] 1656 self._CurrentCursor.setNonUpdateFields(fldList) 1653 for crs in self.__cursors.values(): 1654 crs.setNonUpdateFields(fldList) 1657 1655 1658 1656 … … 1822 1820 1823 1821 AutoQuoteNames = property(_getAutoQuoteNames, _setAutoQuoteNames, None, 1824 _("""When True (default), table and column names are enclosed with 1822 _("""When True (default), table and column names are enclosed with 1825 1823 quotes during SQL creation in the cursor. (bool)""")) 1826 1824 1827 1825 AutoSQL = property(_getAutoSQL, None, None, 1828 1826 _("Returns the SQL statement automatically generated by the sql manager.")) … … 1853 1851 1) The explicitly-set DataStructure property 1854 1852 2) The backend table method""")) 1855 1853 1856 1854 DefaultValues = property(_getDefaultValues, _setDefaultValues, None, 1857 1855 _("""A dictionary specifying default values for fields when a new record is added. … … 1866 1864 FillLinkFromParent = property(_getFillLinkFromParent, _setFillLinkFromParent, None, 1867 1865 _("""In the onNew() method, do we fill in the foreign key field specified by the 1868 LinkField property with the value returned by calling the bizobj's getParentPK() 1866 LinkField property with the value returned by calling the bizobj's getParentPK() 1869 1867 method? (bool)""")) 1870 1868 … … 1901 1899 _("""Represents a record in the data set. You can address individual 1902 1900 columns by referring to 'self.Record.fieldName' (read-only) (no type)""")) 1903 1901 1904 1902 RequeryChildOnSave = property(_getRequeryChildOnSave, _setRequeryChildOnSave, None, 1905 1903 _("Do we requery child bizobjs after a Save()? (bool)")) … … 1929 1927 1930 1928 SaveNewUnchanged = property(_getSaveNewUnchanged, _setSaveNewUnchanged, None, 1931 _("""Normally new, unmodified records are not saved. If you need 1929 _("""Normally new, unmodified records are not saved. If you need 1932 1930 this behavior, set this to True. (bool)""")) 1933 1931 1934 1932 ScanRestorePosition = property(_getScanRestorePosition, _setScanRestorePosition, None, 1935 _("""After running a scan, do we attempt to restore the record position to 1936 where it was before the scan (True, default), or do we leave the pointer 1933 _("""After running a scan, do we attempt to restore the record position to 1934 where it was before the scan (True, default), or do we leave the pointer 1937 1935 at the end of the recordset (False). (bool)""")) 1938 1936 1939 1937 ScanReverse = property(_getScanReverse, _setScanReverse, None, 1940 1938 _("""Do we scan the records in reverse order? (Default: False) (bool)""")) … … 1952 1950 _("""A dictionary mapping virtual_field_name to function to call. 1953 1951 1954 The specified function will be called when getFieldVal() is called on 1952 The specified function will be called when getFieldVal() is called on 1955 1953 the specified virtual field name.""")) 1956 1954 … … 1968 1966 self.__nextfunc = self._prior 1969 1967 return self 1970 1968 1971 1969 1972 1970 def _prior(self): … … 1983 1981 raise StopIteration 1984 1982 return self.obj.RowNumber 1985 1983 1986 1984 1987 1985 def _next(self): … … 1998 1996 raise StopIteration 1999 1997 return self.obj.RowNumber 2000 2001 1998 1999 2002 2000 def next(self): 2003 2001 return self.__nextfunc() 2004 2002 2005 2003 2006 2004 def __iter__(self):
