dabo Commit
Revision 7112
Date: 2012-03-12 16:08:23 -0700 (Mon, 12 Mar 2012)
Author: Paul
Trac: http://trac.dabodev.com/changeset/7112
Changed:
U trunk/dabo/biz/dBizobj.py
Log:
Added biz.CascadeDeleteFromParent property, to allow different settings for
different children.
Sometimes I make children for the purpose of having a convenient lookup, such
as:
bizOrders.addChild(bizCustomers())
I wanted to keep this convenience but still be able to delete an order without
deleting the corresponding customer record. I couldn't just set the the
deletechildlogic on bizOrders to "IGNORE" because there are children that I do
want to cascade the deletes to.
So now I've changed that call to:
bizOrders.addChild(bizCustomers(..., CascadeDeleteFromParent=False))
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2012-03-12 20:15:04 UTC (rev 7111)
+++ trunk/dabo/biz/dBizobj.py 2012-03-12 23:08:23 UTC (rev 7112)
@@ -31,6 +31,7 @@
""" User code should override beforeInit() and/or afterInit()
instead."""
self.__att_try_setFieldVal = False
self._visitedKeys = set()
+ self._cascadeDeleteFromParent = True
# Collection of cursor objects. MUST be defined first.
self.__cursors = {}
# PK of the currently-selected cursor
@@ -628,7 +629,7 @@
if self.deleteChildLogic == kons.REFINTEG_RESTRICT:
# See if there are any child records
for child in self._children:
- if child.RowCount > 0:
+ if child.CascadeDeleteFromParent and
child.RowCount > 0:
raise dException.dException(
_("Deletion prohibited
- there are related child records."))
@@ -642,10 +643,8 @@
# ensure that any changed data they may have is
reverted. They are then requeried to
# populate them with data for the current record in
this bizobj.
for child in self._children:
- if self.deleteChildLogic ==
kons.REFINTEG_CASCADE:
+ if self.deleteChildLogic ==
kons.REFINTEG_CASCADE and child.CascadeDeleteFromParent:
child.deleteAll(startTransaction=False)
- else:
- child.cancelAll()
if startTransaction:
self.commitTransaction()
self.requeryAllChildren()
@@ -2659,6 +2658,13 @@
self._caption = u"%s" % val
+ def _getCascadeDeleteFromParent(self):
+ return self._cascadeDeleteFromParent
+
+ def _setCascadeDeleteFromParent(self, val):
+ self._cascadeDeleteFromParent = bool(val)
+
+
def _getChildCacheInterval(self):
return self._childCacheInterval
@@ -3052,6 +3058,10 @@
Caption = property(_getCaption, _setCaption, None,
_("The friendly title of the cursor, used in messages
to the end user. (str)"))
+ CascadeDeleteFromParent = property(_getCascadeDeleteFromParent,
_setCascadeDeleteFromParent, None,
+ _("""Specifies whether deletion of the parent bizobj
will cascade to delete all
+ linked child records."""))
+
ChildCacheInterval = property(_getChildCacheInterval,
_setChildCacheInterval, None,
_("""If this is a child bizobj, this represents the
length of time in seconds that a
requery from parent.requeryAllChildren() will be
ignored. (int)
_______________________________________________
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]