[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8521 - in trunk/gnue-forms/src: . GFObjects
From: |
reinhard |
Subject: |
[gnue] r8521 - in trunk/gnue-forms/src: . GFObjects |
Date: |
Thu, 29 Jun 2006 08:35:26 -0500 (CDT) |
Author: reinhard
Date: 2006-06-29 08:35:25 -0500 (Thu, 29 Jun 2006)
New Revision: 8521
Modified:
trunk/gnue-forms/src/GFForm.py
trunk/gnue-forms/src/GFInstance.py
trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Cleanup of commit and rollback functions so they can safely be used from
within triggers.
issue79 in-progress
Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py 2006-06-29 10:06:26 UTC (rev 8520)
+++ trunk/gnue-forms/src/GFForm.py 2006-06-29 13:35:25 UTC (rev 8521)
@@ -39,6 +39,20 @@
from gnue.common.utils import CaselessDict
# =============================================================================
+# Exceptions
+# =============================================================================
+
+class ReadOnlyError(errors.ApplicationError):
+ """
+ Form is read only.
+
+ A trigger attempted to call the C{commit()} function of a read only form.
+ """
+ def __init__(self):
+ errors.ApplicationError.__init__(self, u_("Form is read only"))
+
+
+# =============================================================================
# Implementation of the form tag
# =============================================================================
@@ -959,7 +973,7 @@
# Does a connection have any pending (already posted but not yet
committed)
# changes?
- for connection in (self.__getConnections ()).values ():
+ for connection in (self.__get_connections ()).values ():
if connection.isPending ():
return False
@@ -1088,123 +1102,119 @@
def commit(self):
"""
- Commits all pending changes.
- @return: None if all went well, error message otherwise
+ Commit all pending changes.
"""
- assert gEnter (4)
-
if not self.endEditing():
return
+ # It is not possible to make any record dirty in any way if the form is
+ # read only, so the menu item and the toolbar button for committing are
+ # never active for a read only form. Still, any other trigger could
+ # call commit() manually, in which case this exception would occur.
if self.readonly:
- return _('Form is readonly')
+ raise ReadOnlyError
- message = None
newBlock = None # block to jump to after commit
try:
- # Save all current records, since they get lost in the Pre-Commit
code
- for block in self._logic._blockList:
- block._precommitRecord = block._currentRecord
+ # Save all current records, since they get lost in the Pre-Commit
+ # trigger code
+ for block in self._logic._blockList:
+ block._precommitRecord = block._currentRecord
- # Form level pre-commit triggers
- try:
- self.processTrigger ('Pre-Commit', ignoreAbort = False)
+ # Form level pre-commit triggers
+ self.processTrigger('Pre-Commit', ignoreAbort=False)
- except AbortRequest:
- assert gDebug (5, "Trigger form Pre-Commit threw a AbortRequest!")
- message = u_("Form trigger returned error")
+ # Process the commit on all blocks
+ for block in self._logic._blockList:
+ assert gDebug(5, "Saving %s" % block.name)
+ try:
+ block.processCommit()
+ except Exception:
+ # jump to offending block
+ newBlock = block
+ raise
-
- # Process the commit on all blocks
- for block in self._logic._blockList:
- assert gDebug (5, "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 connection in self.__get_connections().values():
+ connection.commit()
- except AbortRequest:
- assert gDebug (5, "Trigger block Pre-Commit threw a
AbortRequest!")
- message = u_("Block trigger returned error")
- # jump to offending block
- newBlock = block
except:
- # jump to offending block
- newBlock = block
- raise
+ # Make sure the block is in consistent state again; this has to
+ # be done in any case if the processCommit was successful, even
+ # if the connection commit failed!
+ for block in self._logic._blockList:
+ block.finalizeCommit(False)
+ raise
- try:
- # 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:
- # Make sure the block is in consistent state again; this has to be
- # done in any case if the processCommit was successful, even if the
- # connection commit failed!
for block in self._logic._blockList:
- block.finalizeCommit (False)
- raise
+ block.finalizeCommit(True)
- for block in self._logic._blockList:
- block.finalizeCommit (True)
+ # Execute Post-Commit-Trigger for each block
+ for block in self._logic._blockList:
+ block.processTrigger('Post-Commit')
- # Execute Post-Commit-Trigger for each block
- for block in self._logic._blockList:
- 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 ()
+ self.dispatchEvent('cannotCOMMIT')
+ self.dispatchEvent('cannotROLLBACK')
- self.dispatchEvent ('cannotCOMMIT')
- self.dispatchEvent ('cannotROLLBACK')
+ # Execute Post-Commit-Trigger for the form
+ self.processTrigger('Post-Commit')
- # Execute Post-Commit-Trigger for the form
- self.processTrigger ('Post-Commit')
-
finally:
- # Make sure the current block still has the focus, even if an
exception
- # occured during commit or in a trigger
- if newBlock is not None and newBlock != self._currentBlock:
- self.findAndChangeFocus (newBlock)
+ # In case the commit failed for a different block than the current
+ # one, jump to that block.
+ if newBlock is not None and newBlock != self._currentBlock:
+ self.findAndChangeFocus(newBlock)
- assert gLeave (4)
+ self.refreshDisplay(self)
+ self.update_record_counter()
+ self.update_record_status()
+ self.dispatchEvent('gotoENTRY', object=self._currentEntry,
_form=self)
+ self.beginEditing()
- return message
-
# -------------------------------------------------------------------------
- # Rolls back any uncommitted transatcion
+ # Roll back any uncommitted transaction
# -------------------------------------------------------------------------
- def rollback (self, recover = False):
+ def rollback(self, recover=False):
"""
- Rolls back any uncommitted transaction.
- @return: None
+ Roll back any uncommitted transaction.
"""
+
self.endEditing()
- # Call rollback only once per connection (if multiple blocks are
sharing
- # the same connection)
- for (cName, connection) in self.__getConnections ().items ():
- connection.rollback ()
+ # Call rollback only once per connection (if multiple blocks are
+ # sharing the same connection)
+ for connection in self.__get_connections().values():
+ connection.rollback()
for block in self._logic._blockList:
- block.processRollback (recover, backendRollback = False)
+ block.processRollback(recover, backendRollback=False)
- self.refreshDisplay (self)
- self._currentBlock.jumpRecord(self._currentBlock._currentRecord)
- self.dispatchEvent ('cannotCOMMIT')
- self.dispatchEvent ('cannotROLLBACK')
+ self.dispatchEvent('cannotCOMMIT')
+ self.dispatchEvent('cannotROLLBACK')
+ self.refreshDisplay(self)
+ self.update_record_counter()
+ self.update_record_status()
+ self.dispatchEvent ('gotoENTRY', object=self._currentEntry, _form=self)
+ self.beginEditing()
+
# -------------------------------------------------------------------------
# Get all connections used by the form
# -------------------------------------------------------------------------
- def __getConnections (self):
+ def __get_connections(self):
"""
This function creates a dictionary of all connections referenced by the
form, where the connection-name is the key and the connection instance
@@ -1220,8 +1230,7 @@
result [dLink.connection] = dLink._connection
except AttributeError:
pass
-
-
+
return result
Modified: trunk/gnue-forms/src/GFInstance.py
===================================================================
--- trunk/gnue-forms/src/GFInstance.py 2006-06-29 10:06:26 UTC (rev 8520)
+++ trunk/gnue-forms/src/GFInstance.py 2006-06-29 13:35:25 UTC (rev 8521)
@@ -822,7 +822,6 @@
# TODO: WTF? This isn't saving a currently edited field
if event._form._currentBlock.autoCommit and not event._form.isSaved ():
- event._form.endEditing ()
event._form.commit ()
if not event._form.isSaved ():
@@ -988,18 +987,6 @@
# ---------------------------------------------------------------------------
- # Perform a rollback
- # ---------------------------------------------------------------------------
-
- def executeRollback (self, event):
- """
- Tells the form to rollback everything it contains
- """
- event._form.rollback ()
- self._entryUpdated (event._form)
-
-
- # ---------------------------------------------------------------------------
# Change the focus to an entry object
# ---------------------------------------------------------------------------
@@ -1120,17 +1107,20 @@
def executeCommit (self, event):
- try:
- message = event._form.commit ()
- if message:
- self.displayMessageBox (message, 'Error')
- assert gDebug(4,message)
+ event._form.commit ()
- finally:
- self._entryUpdated (event._form)
- event._form.refreshDisplay (event._form._currentBlock)
+ # ---------------------------------------------------------------------------
+ # Perform a rollback
+ # ---------------------------------------------------------------------------
+ def executeRollback (self, event):
+ """
+ Tells the form to rollback everything it contains
+ """
+ event._form.rollback ()
+
+
# ---------------------------------------------------------------------------
# Execute user command
# ---------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-06-29 10:06:26 UTC (rev
8520)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-06-29 13:35:25 UTC (rev
8521)
@@ -779,7 +779,7 @@
# Move to correct record in grid
self._form.findAndChangeFocus (self._form._currentEntry)
- self._form.update_record_counter(self._form)
+ self._form.update_record_counter()
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8521 - in trunk/gnue-forms/src: . GFObjects,
reinhard <=