dabo Commit
Revision 7087
Date: 2012-02-08 16:19:25 -0800 (Wed, 08 Feb 2012)
Author: Paul
Trac: http://trac.dabodev.com/changeset/7087
Changed:
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/ui/uiwx/dForm.py
Log:
Opened up the ability to specify in dForm whether canceling and saving will
cancel/save children. My main form has a number of children in the hierarchy
with unlimited rows in each, but data changed in these sub-bizobjs is
automatically saved or canceled already, so there's no need to check for
those changes when the user clicks "save" or "cancel": all they want to do
is save or cancel master information they've entered explicitly.
The performance still isn't great, as biz.saveAll() still iterates every
master row, but it is an improvement.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2012-02-08 23:36:02 UTC (rev 7086)
+++ trunk/dabo/biz/dBizobj.py 2012-02-09 00:19:25 UTC (rev 7087)
@@ -412,9 +412,9 @@
del(dabo._bizTransactionToken)
- def saveAll(self, startTransaction=True):
+ def saveAll(self, startTransaction=True, saveTheChildren=True):
"""
- Saves all changes to the bizobj and children.
+ Save changes to all rows in the bizobj, and (by default) the
children.
"""
# JKA: I can't see any sense in using 'scanChangedRows()' here,
since
# we must check for changes in 'save()' method too.
@@ -431,7 +431,8 @@
startTransaction = startTransaction and self.beginTransaction()
try:
- self.scan(self.save, startTransaction=False,
scanRequeryChildren=False)
+ self.scan(self.save, startTransaction=False,
+ saveTheChildren=saveTheChildren,
scanRequeryChildren=False)
if startTransaction:
self.commitTransaction()
except dException.ConnectionLostException:
@@ -518,18 +519,18 @@
self.afterSave()
- def cancelAll(self, ignoreNoRecords=None):
+ def cancelAll(self, ignoreNoRecords=None, cancelTheChildren=True):
"""
- Cancel all changes made to the current dataset, including all
children
+ Cancel all changes made in all rows, including by default all
children
and all new, unmodified records.
"""
self.scanChangedRows(self.cancel, allCursors=False,
includeNewUnchanged=True,
- ignoreNoRecords=ignoreNoRecords, reverse=True)
+ cancelTheChildren=cancelTheChildren,
ignoreNoRecords=ignoreNoRecords, reverse=True)
- def cancel(self, ignoreNoRecords=None):
+ def cancel(self, ignoreNoRecords=None, cancelTheChildren=True):
"""
- Cancel all changes to the current record and all children.
+ Cancel all changes to the current record and by default all
children.
Two hook methods will be called: beforeCancel() and
afterCancel(). The
former, if it returns an error message, will raise an exception
and not
@@ -544,8 +545,9 @@
ignoreNoRecords = True
# Tell the cursor and all children to cancel themselves:
self._CurrentCursor.cancel(ignoreNoRecords=ignoreNoRecords)
- for child in self._children:
- child.cancelAll(ignoreNoRecords=ignoreNoRecords)
+ if cancelTheChildren:
+ for child in self._children:
+ child.cancelAll(ignoreNoRecords=ignoreNoRecords)
self.afterCancel()
Modified: trunk/dabo/ui/uiwx/dForm.py
===================================================================
--- trunk/dabo/ui/uiwx/dForm.py 2012-02-08 23:36:02 UTC (rev 7086)
+++ trunk/dabo/ui/uiwx/dForm.py 2012-02-09 00:19:25 UTC (rev 7087)
@@ -167,7 +167,7 @@
changedBizList = []
for biz in bizList:
- if biz and biz.isAnyChanged():
+ if biz and
biz.isAnyChanged(withChildren=self.SaveChildren):
changedBizList.append(biz)
if changedBizList:
@@ -425,11 +425,12 @@
if err:
self.notifyUser(err)
return False
+
try:
if self.SaveAllRows:
- bizobj.saveAll()
+
bizobj.saveAll(saveTheChildren=self.SaveChildren)
else:
- bizobj.save()
+ bizobj.save(saveTheChildren=self.SaveChildren)
self.setStatusText(_("Changes to %s saved.") % (
self.SaveAllRows and "all records" or
"current record",))
@@ -478,9 +479,11 @@
return
try:
if self.SaveAllRows:
-
bizobj.cancelAll(ignoreNoRecords=ignoreNoRecords)
+
bizobj.cancelAll(ignoreNoRecords=ignoreNoRecords,
+
cancelTheChildren=self.CancelChildren)
else:
- bizobj.cancel(ignoreNoRecords=ignoreNoRecords)
+ bizobj.cancel(ignoreNoRecords=ignoreNoRecords,
+
cancelTheChildren=self.CancelChildren)
self.update()
self.setStatusText(_("Changes to %s canceled.") % (
self.SaveAllRows and "all records" or
"current record",))
@@ -883,6 +886,16 @@
# Property get/set/del functions follow.
+ def _getCancelChildren(self):
+ try:
+ return self._CancelChildren
+ except AttributeError:
+ return True
+
+ def _setCancelChildren(self, value):
+ self._CancelChildren = bool(value)
+
+
def _getCheckForChanges(self):
return self._checkForChanges
@@ -956,7 +969,20 @@
self._SaveAllRows = bool(value)
+ def _getSaveChildren(self):
+ try:
+ return self._SaveChildren
+ except AttributeError:
+ return True
+
+ def _setSaveChildren(self, value):
+ self._SaveChildren = bool(value)
+
+
# Property definitions:
+ CancelChildren = property(_getCancelChildren, _setCancelChildren, None,
+ _("Specifies whether changes are canceled from child
bizobjs. (bool; default:True)"))
+
CheckForChanges = property(_getCheckForChanges, _setCheckForChanges,
None,
_("""Specifies whether the user is prompted to save or
discard changes. (bool)
@@ -1001,10 +1027,13 @@
"""))
SaveAllRows = property(_getSaveAllRows, _setSaveAllRows, None,
- _("Specifies whether dataset is row- or table-buffered.
(bool)"))
+ _("Specifies whether changes are saved to all rows, or
just the current row. (bool)"))
+ SaveChildren = property(_getSaveChildren, _setSaveChildren, None,
+ _("Specifies whether changes are saved to child
bizobjs. (bool; default:True)"))
+
class dForm(BaseForm, wx.Frame):
def __init__(self, parent=None, properties=None, attProperties=None,
*args, **kwargs):
self._baseClass = dForm
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]