Changeset 3074
- Timestamp:
- 04/21/07 05:49:42 (2 years ago)
- Files:
-
- trunk/dabo/biz/dBizobj.py (modified) (10 diffs)
- trunk/dabo/db/dCursorMixin.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/biz/dBizobj.py
r3070 r3074 264 264 265 265 try: 266 self.scanChangedRows(self.save, startTransaction=False, topLevel=False) 266 self.scanChangedRows(self.save, includeNewUnchanged=self.SaveNewUnchanged, 267 startTransaction=False, topLevel=False) 267 268 except dException.ConnectionLostException, e: 268 269 self.RowNumber = current_row … … 366 367 367 368 def cancelAll(self, ignoreNoRecords=None): 368 """Cancel all changes made to the current dataset, including all children.""" 369 self.scanChangedRows(self.cancel, allCursors=False, ignoreNoRecords=ignoreNoRecords) 369 """Cancel all changes made to the current dataset, including all children 370 and all new, unmodified records. 371 """ 372 self.scanChangedRows(self.cancel, allCursors=False, includeNewUnchanged=True, 373 ignoreNoRecords=ignoreNoRecords) 370 374 371 375 … … 497 501 498 502 499 def getChangedRows(self ):500 """ Returns a list of row numbers for which isChanged() returns True. The503 def getChangedRows(self, includeNewUnchanged=False): 504 """ Returns a list of row numbers for which isChanged() returns True. The 501 505 changes may therefore not be in the record itself, but in a dependent child 502 record. 506 record. If includeNewUnchanged is True, the presence of a new unsaved 507 record that has not been modified from its defaults will suffice to mark the 508 record as changed. 503 509 """ 504 510 if self.__children: … … 509 515 else: 510 516 # Can use the much faster cursor.getChangedRows(): 511 return self._CurrentCursor.getChangedRows( )517 return self._CurrentCursor.getChangedRows(includeNewUnchanged) 512 518 513 519 … … 587 593 588 594 589 def scanChangedRows(self, func, allCursors=False, *args, **kwargs): 595 def scanChangedRows(self, func, allCursors=False, includeNewUnchanged=False, 596 *args, **kwargs): 590 597 """Move the record pointer to each changed row, and call func. 591 598 592 599 If allCursors is True, all other cursors for different parent records will 593 be iterated as well. 600 be iterated as well. 601 602 If includeNewUnchanged is True, new unsaved records that have not been 603 edited from their default values will be counted as 'changed'. 594 604 595 605 If you want to end the scan on the next iteration, set self.exitScan=True. … … 614 624 for key, cursor in cursors.iteritems(): 615 625 self._CurrentCursor = key 616 changedRows = self.getChangedRows( )626 changedRows = self.getChangedRows(includeNewUnchanged) 617 627 for row in changedRows: 618 628 self._moveToRowNum(row) … … 942 952 return False 943 953 944 if cc.isChanged(allRows=True ):954 if cc.isChanged(allRows=True, includeNewUnchanged=self.SaveNewUnchanged): 945 955 return True 946 956 … … 972 982 # No cursor, no changes. 973 983 return False 974 ret = cc.isChanged(allRows=False )984 ret = cc.isChanged(allRows=False, includeNewUnchanged=self.SaveNewUnchanged) 975 985 976 986 if not ret: … … 1719 1729 1720 1730 1731 def _getSaveNewUnchanged(self): 1732 try: 1733 ret = self._saveNewUnchanged 1734 except AttributeError: 1735 ret = self._saveNewUnchanged = False 1736 return ret 1737 1738 def _setSaveNewUnchanged(self, val): 1739 self._saveNewUnchanged = val 1740 1741 1721 1742 def _getSQL(self): 1722 1743 try: … … 1870 1891 _("The current position of the record pointer in the result set. (int)")) 1871 1892 1893 SaveNewUnchanged = property(_getSaveNewUnchanged, _setSaveNewUnchanged, None, 1894 _("""Normally new, unmodified records are not saved. If you need 1895 this behavior, set this to True. (bool)""")) 1896 1872 1897 SQL = property(_getSQL, _setSQL, None, 1873 1898 _("SQL statement used to create the cursor's data. (str)")) trunk/dabo/db/dCursorMixin.py
r3066 r3074 610 610 611 611 612 def isChanged(self, allRows=True ):612 def isChanged(self, allRows=True, includeNewUnchanged=False): 613 613 """Return True if there are any changes to the local field values. 614 614 615 615 If allRows is True (the default), all records in the recordset will be 616 616 considered. Otherwise, only the current record will be checked. 617 618 If includeNewUnchanged is True, new records that have not been 619 modified from their default values, which normally are not 620 considered 'changed', will be counted as 'changed'. 617 621 """ 618 622 if allRows: 619 #return len(self._mementos) > 0 or len(self._newRecords) > 0 620 return len(self._mementos) > 0 623 if includeNewUnchanged: 624 return (len(self._mementos) > 0) or (len(self._newRecords) > 0) 625 else: 626 return len(self._mementos) > 0 621 627 else: 622 628 row = self.RowNumber … … 628 634 return False 629 635 recKey = self.pkExpression(rec) 630 memento = self._mementos.get(recKey, None) 631 return bool(memento) 636 modrec = self._mementos.get(recKey, None) 637 if not modrec and includeNewUnchanged: 638 modrec = self._newRecords.get(recKey, None) 639 return bool(modrec) 632 640 633 641 … … 1390 1398 1391 1399 1392 def getChangedRows(self ):1400 def getChangedRows(self, includeNewUnchanged=False): 1393 1401 """Returns a list of rows with changes.""" 1394 return map(self._getRowByPk, self._mementos.keys()) 1402 chKeys = self._mementos.keys() 1403 if includeNewUnchanged: 1404 # We need to also count all new records 1405 chKeys = dict.fromkeys(chKeys + self._newRecords.keys()).keys() 1406 return map(self._getRowByPk, chKeys) 1395 1407 1396 1408
