[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r6878 - in trunk/gnue-forms/src: . GFObjects
From: |
johannes |
Subject: |
[gnue] r6878 - in trunk/gnue-forms/src: . GFObjects |
Date: |
Sun, 9 Jan 2005 13:12:33 -0600 (CST) |
Author: johannes
Date: 2005-01-09 13:12:32 -0600 (Sun, 09 Jan 2005)
New Revision: 6878
Modified:
trunk/gnue-forms/src/GFForm.py
trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
form.commit () only does a single commit () per backend-connection. Made
block.commit () to call a form.commit () giving a depreciation warning
Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py 2005-01-09 19:10:42 UTC (rev 6877)
+++ trunk/gnue-forms/src/GFForm.py 2005-01-09 19:12:32 UTC (rev 6878)
@@ -617,48 +617,60 @@
Commits all pending changes.
@return: None if all went well, error message otherwise
"""
+
+ self.endEditing ()
+ if self.readonly:
+ return _('Form is readonly')
+
message = None
self.dispatchEvent ('beginWAIT', _form = self)
try:
try:
- if not self.readonly:
- for block in self._logic._blockList:
- # This gets lost in the Pre-Commit code
- block._precommitRecord = block._currentRecord
- # Form level pre-commit
+ # Save all current records, since they get lost in the Pre-Commit code
+ for block in self._logic._blockList:
+ block._precommitRecord = block._currentRecord
+
+ # Form level pre-commit triggers
+ try:
+ self.processTrigger ('Pre-Commit', ignoreAbort = False)
+
+ except AbortRequest:
+ gDebug (1, "Trigger form Pre-Commit threw a AbortRequest!")
+ return _("Form trigger returned error")
+
+
+ # Process the commit on all blocks
+ for block in self._logic._blockList:
+ gDebug (1, "Saving %s" % block.name)
try:
- self.processTrigger ('Pre-Commit', ignoreAbort = False)
+ block.processCommit ()
except AbortRequest:
- gDebug (1, "Trigger form Pre-Commit threw a AbortRequest!")
- return _("Form trigger returned error")
+ gDebug (1, "Trigger block Pre-Commit threw a AbortRequest!")
+ return _("Block trigger returned error")
- for block in self._logic._blockList:
- gDebug (1, "Saving %s" % block.name)
- try:
- block.processCommit ()
+ # Now do the real commit () on the backend connections (only once per
+ # connection, if multiple blocks are sharing the same connection)
+ for conn in self.__getConnections ().values ():
+ conn.commit ()
- except AbortRequest:
- gDebug (1, "Trigger block Pre-Commit threw a AbortRequest!")
- return _("Block trigger returned error")
+ # Execute Post-Commit-Trigger for each block
+ for block in self._logic._blockList:
+ block.processTrigger ('Post-Commit')
- block.processTrigger ('Post-Commit')
+ for block in self._logic._blockList:
+ if block.autoClear:
+ block.processClear ()
- for block in self._logic._blockList:
- if block.autoClear:
- block.processClear ()
+ else:
+ gDebug (1, "switchRecord (0) from commit")
+ block.switchRecord (0)
- else:
- gDebug (1, "switchRecord (0) from commit")
- block.switchRecord(0)
+ self.dispatchEvent ('cannotCOMMIT')
+ self.dispatchEvent ('cannotROLLBACK')
- self.dispatchEvent ('cannotCOMMIT')
- self.dispatchEvent ('cannotROLLBACK')
-
- else:
- return _('Form is readonly')
-
+ # Execute Post-Commit-Trigger for the form
self.processTrigger ('Post-Commit')
except DBError:
@@ -668,6 +680,9 @@
'exMessage': sys.exc_info ()[1]}
finally:
+ # Make sure the current block still has the focus, even if an exception
+ # occured during commit or in a trigger
+ self.findAndChangeFocus (self._currentBlock)
self.dispatchEvent ('endWAIT', _form = self)
return message
@@ -683,15 +698,9 @@
"""
self.endEditing()
- # First get all different connections
- conns = {}
- for block in self._logic._blockList:
- dLink = block._dataSourceLink
- if not conns.has_key (dLink.connection) and \
- dLink._dataObject._connection is not None:
- conns [dLink.connection] = dLink._dataObject._connection
-
- for (cName, connection) in conns.items ():
+ # Call rollback only once per connection (if multiple blocks are sharing
+ # the same connection)
+ for (cName, connection) in self.__getConnections ().items ():
connection.rollback ()
for block in self._logic._blockList:
@@ -703,6 +712,30 @@
self.dispatchEvent ('cannotROLLBACK')
+ # ---------------------------------------------------------------------------
+ # Get all connections used by the form
+ # ---------------------------------------------------------------------------
+
+ def __getConnections (self):
+ """
+ This function creates a dictionary of all connections used by the form's
+ blocks, where the connection-name is the key and the connection instance is
+ the value.
+
+ @return: dictionary with all connections used by the form
+ """
+
+ result = {}
+
+ for block in self._logic._blockList:
+ dLink = block._dataSourceLink
+ if not result.has_key (dLink.connection) and \
+ dLink._dataObject._connection is not None:
+ result [dLink.connection] = dLink._dataObject._connection
+
+ return result
+
+
#---------------------------------------------------------------------------
# Launch a trigger
#---------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py 2005-01-09 19:10:42 UTC (rev
6877)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2005-01-09 19:12:32 UTC (rev
6878)
@@ -1,6 +1,9 @@
+# GNU Enterprise Forms - GF Class Hierarchy - Block
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2005 Free Software Foundation
#
+# This file is part of GNU Enterprise
+#
# GNU Enterprise is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
@@ -16,19 +19,10 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2000-2005 Free Software Foundation
-#
-# FILE:
-# GFBlock.py
-#
-# DESCRIPTION:
+# $Id: $
"""
Classes making up the Block object
"""
-# NOTES:
-#
-# HISTORY:
-#
from gnue.forms.GFObjects.GFDataSource import GFDataSource
@@ -474,6 +468,10 @@
self.processTrigger('POST-FOCUSIN')
def commit(self):
+ print "DEPRECIATION WARNING: the use of block.commit () is depreciated.", \
+ "Please use form.commit () instead."
+ self._form.commit ()
+
#Commented out (dimas)
#Does not work properly anyway
#self._form.changeFocus(self)
@@ -482,10 +480,9 @@
#TODO: Add error handling
#TODO: Check how triggers performed
#TODO: original code is in GFForm.commit
- self._precommitRecord = self._currentRecord
+ #self._precommitRecord = self._currentRecord
+ #self.processCommit()
- self.processCommit()
-
def jumpRecord(self, recordNumber):
# If recordNumber is negative, move relative to last record
if recordNumber < 0:
@@ -543,7 +540,8 @@
if not self._dataSourceLink.hasMaster():
self._resultSet.post()
- self._dataSourceLink._dataObject.commit()
+ # The real commit will be done by the form once per connection
+ # self._dataSourceLink._dataObject.commit()
self._recordCount = self._resultSet.getRecordCount()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r6878 - in trunk/gnue-forms/src: . GFObjects,
johannes <=