[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8649 - in trunk/gnue-forms/src: . GFObjects
From: |
reinhard |
Subject: |
[gnue] r8649 - in trunk/gnue-forms/src: . GFObjects |
Date: |
Mon, 4 Sep 2006 16:42:42 -0500 (CDT) |
Author: reinhard
Date: 2006-09-04 16:42:41 -0500 (Mon, 04 Sep 2006)
New Revision: 8649
Modified:
trunk/gnue-forms/src/GFForm.py
trunk/gnue-forms/src/GFInstance.py
trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Cleanup of "newRecord" procedures, first step of restructuring GFBlock.
Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py 2006-09-04 18:59:22 UTC (rev 8648)
+++ trunk/gnue-forms/src/GFForm.py 2006-09-04 21:42:41 UTC (rev 8649)
@@ -980,14 +980,16 @@
# -------------------------------------------------------------------------
# Create a new, empty record
# -------------------------------------------------------------------------
- def newRecord(self):
+
+ def new_record(self):
"""
- Creates a new, empty record.
+ Create a new, empty record in the current block.
"""
- if not self.readonly and self._currentBlock is not None:
- self._currentBlock.newRecord()
+ if self._currentBlock is not None:
+ self._currentBlock.new_record()
+
# -------------------------------------------------------------------------
# Delete the current record.
# -------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/GFInstance.py
===================================================================
--- trunk/gnue-forms/src/GFInstance.py 2006-09-04 18:59:22 UTC (rev 8648)
+++ trunk/gnue-forms/src/GFInstance.py 2006-09-04 21:42:41 UTC (rev 8649)
@@ -855,19 +855,9 @@
"""
Tells the form to create a new record
"""
+ event._form.new_record()
- if not event._form.endEditing ():
- return
- if event._form.readonly:
- event._form.alert_message(u_("Form is readonly"))
- elif event._form._currentBlock.editable not in ('Y', 'new'):
- event._form.alert_message(u_('Block does not allow insert'))
- else:
- event._form.newRecord()
- self._entryUpdated(event._form)
-
-
# ---------------------------------------------------------------------------
# Display the about dialog
# ---------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-09-04 18:59:22 UTC (rev
8648)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-09-04 21:42:41 UTC (rev
8649)
@@ -124,7 +124,7 @@
'function' : self.commit,
'description': ''},
'newRecord': {
- 'function' : self.newRecord,
+ 'function' : self.new_record,
'description': ''},
'deleteRecord': {
'function' : self.deleteRecord,
@@ -184,7 +184,7 @@
'function' : self.updateCurrentRecordSet,
'description': ''},
'get_data': {
- 'function': self.trigger_get_data,
+ 'function': self.get_data,
'description': 'Export current result set into a list of dicts'}
}
@@ -338,7 +338,6 @@
child._gap = getattr (child, 'rowSpacer', self._gap)
-
# ---------------------------------------------------------------------------
# Event handling functions for datasource events
# ---------------------------------------------------------------------------
@@ -350,9 +349,9 @@
recno = self._resultSet.getRecordNumber ()
if recno == -1:
if not self._resultSet.firstRecord ():
- self.newRecord ()
+ self.new_record()
else:
- self.switchRecord (recno - self._currentRecord)
+ self.__switch_record (recno - self._currentRecord)
self._form.update_record_counter()
self._form.update_record_status()
@@ -366,9 +365,9 @@
recno = self._resultSet.getRecordNumber ()
if recno != -1:
if self.__scrolling:
- self.switchRecord (0)
+ self.__switch_record (0)
else:
- self.switchRecord (recno - self._currentRecord)
+ self.__switch_record (recno - self._currentRecord)
# ---------------------------------------------------------------------------
@@ -460,7 +459,7 @@
newVisibleStart = self._currentRecord - self._rows + 1
if newVisibleStart != self.__visibleStart:
- self.switchRecord (self.__visibleStart - newVisibleStart)
+ self.__switch_record (self.__visibleStart - newVisibleStart)
# Now we have to move the record pointer to keep it in the visible portion
if position != self.__visibleStart:
@@ -475,12 +474,10 @@
self._form.findAndChangeFocus (self._form._currentEntry)
+ # ---------------------------------------------------------------------------
+ # Status information
+ # ---------------------------------------------------------------------------
-
- # ===========================================================================
- # Trigger functions
- # ===========================================================================
-
def isSaved (self):
"""
Returns True if the datasource the block is associated with is not pending
@@ -518,6 +515,15 @@
# ---------------------------------------------------------------------------
+ def isFirstRecord (self):
+ """
+ Returns True if the current record is the first one in the ResultSet
+ """
+
+ return self._resultSet.isFirstRecord ()
+
+ # ---------------------------------------------------------------------------
+
def isLastRecord (self):
"""
Returns True if the current record is the last one in the ResultSet.
@@ -527,34 +533,49 @@
# ---------------------------------------------------------------------------
- def isFirstRecord (self):
+ def getResultSet (self):
"""
- Returns True if the current record is the first one in the ResultSet
+ Return the current ResultSet of the block.
"""
- return self._resultSet.isFirstRecord ()
+ return self._resultSet
# ---------------------------------------------------------------------------
- def lastRecord (self):
- """
- Move to the last record of the block. Pre- and Post-Focusout triggers are
- fired before moving as well as Pre- and Post-Focusin triggers after moving
- the record pointer.
- """
+ def get_data(self, fieldnames):
+ """
+ Build a list of dictionaries of the current resultset using the fields
+ defined by fieldnames.
- if not self._resultSet.isLastRecord ():
- # Do FocusOut triggers
- self.processTrigger ('PRE-FOCUSOUT')
- self.processTrigger ('POST-FOCUSOUT')
+ @param fieldnames: list of fieldnames to export per record
+ @returns: list of dictionaries (one per record)
+ """
- self._resultSet.lastRecord ()
+ result = []
+ if not fieldnames:
+ fields = self._fieldMap.values()
+ else:
+ fields = [self._fieldMap[fld] for fld in fieldnames]
- # Focus in
- self.processTrigger ('PRE-FOCUSIN')
- self.processTrigger ('POST-FOCUSIN')
+ for r in self._resultSet:
+ add = {}
+ for field in fields:
+ fname = field.field
+ if hasattr(field, 'fk_source'):
+ value = field._allowedValues.get(r[fname])
+ else:
+ value = r[fname]
+ add[fname] = value
+
+ result.append(add)
+
+ return result
+
+
# ---------------------------------------------------------------------------
+ # Record Navigation
+ # ---------------------------------------------------------------------------
def firstRecord (self):
"""
@@ -621,144 +642,34 @@
elif self.autoCreate and not self.isEmpty () and \
not self.editable in ('update', 'N'):
- self.newRecord ()
+ self.new_record()
# Go to first field
# TODO: check if this is really what we want to have
self._form.findAndChangeFocus (self._entryList [0])
-
# ---------------------------------------------------------------------------
- def deleteRecord (self):
+ def lastRecord (self):
"""
- Mark the current record for deletion. The acutal deletion will be done on
- the next commit, call or update.
+ Move to the last record of the block. Pre- and Post-Focusout triggers are
+ fired before moving as well as Pre- and Post-Focusin triggers after moving
+ the record pointer.
"""
- self._resultSet.current.delete ()
+ if not self._resultSet.isLastRecord ():
+ # Do FocusOut triggers
+ self.processTrigger ('PRE-FOCUSOUT')
+ self.processTrigger ('POST-FOCUSOUT')
- # ---------------------------------------------------------------------------
+ self._resultSet.lastRecord ()
- def undeleteRecord (self):
- """
- Removes the deletion mark from the record
- """
-
- self._resultSet.current.undelete ()
-
-
- # ---------------------------------------------------------------------------
-
- def newRecord (self):
- """
- Add a new record to the block. If autoCommit is set and a record is
- currently pending it will be commited first.
- """
-
- # Focus out
- self.processTrigger ('PRE-FOCUSOUT')
-
- if self.autoCommit and self._resultSet.current:
- self._form.commit ()
-
- self.processTrigger ('POST-FOCUSOUT')
-
- if self._resultSet.insertRecord (self._lastValues):
- self._recordCount = self._resultSet.getRecordCount ()
-
# Focus in
self.processTrigger ('PRE-FOCUSIN')
self.processTrigger ('POST-FOCUSIN')
-
# ---------------------------------------------------------------------------
- def duplicateRecord (self, exclude = (), include = ()):
- """
- Create a new record and initialize it with field values from the record at
- the current cursor position.
-
- @param exclude: list of fields not to copy.
- @param include: list of fields to copy. An empty list means to copy all
- fields except primary key fields and rowid fields, which are never copied
- anyway.
- """
-
- # TODO: check if we need to do autoCommit and fire triggers here too
- self._resultSet.duplicateRecord (exclude = exclude, include = include)
-
-
- # ---------------------------------------------------------------------------
-
- def switchRecord (self, adjustment):
- """
- Moves the proper record into editing position
- """
-
- newRecord = self._resultSet.getRecordNumber ()
- newRecordCount = self._resultSet.getRecordCount ()
-
- self.__visibleStart += newRecord - self._currentRecord - adjustment
-
- self.__visibleStart = min (self.__visibleStart, newRecord)
- self.__visibleStart = max (self.__visibleStart, newRecord - self._rows + 1)
- self.__visibleStart = max (self.__visibleStart, 0)
-
- self._currentRecord = newRecord
- self._recordCount = newRecordCount
-
- for field in self._fieldList:
- field._event_new_current_record ()
-
- for entry in field._entryList:
- # This loop is probably better somewhere else
- entry.recalculate_visible (adjustment, self._currentRecord,
- self._recordCount)
-
- self._form.updateUIEntry (field)
-
- # Ok, don't forgett the buttons here. Since they might be used within a
- # block as well but don't have a corresponding field we need a seperate
- # iteration.
- for entry in self._entryList:
- if entry._type == 'GFButton':
- entry.recalculate_visible (adjustment, self._currentRecord,
- self._recordCount)
-
- self._form.refreshUIEvents ()
-
- # Adjusting scrollbars
- for sb in self._scrollbars:
- sb.do_adjust_scrollbar (self.__visibleStart,
- max (self._recordCount, self.__visibleStart + self._rows))
-
- # ---------------------------------------------------------------------------
-
- def getResultSet (self):
- """
- Return the current ResultSet of the block.
- """
-
- return self._resultSet
-
-
- # ---------------------------------------------------------------------------
-
- def commit (self):
- """
- Commit all pending changes of the form this block is bound to.
-
- This method is depreciated. Please use form.commit () instead.
- """
-
- print "DEPRECIATION WARNING: the use of block.commit () is depreciated.", \
- "Please use form.commit () instead."
- self._form.commit ()
-
-
- # ---------------------------------------------------------------------------
-
def jumpRecord (self, recordNumber):
"""
Jump to a specific record. If the block is the block being currently edited
@@ -792,7 +703,6 @@
self._form.findAndChangeFocus (self._form._currentEntry)
self._form.update_record_counter()
-
# ---------------------------------------------------------------------------
def jumpRecords (self, adjustment):
@@ -810,89 +720,128 @@
self.jumpRecord (targetRecord)
+
# ---------------------------------------------------------------------------
+ # Insertion and Deletion of Records
+ # ---------------------------------------------------------------------------
- def processCommit (self):
- """
- Post all pending changes of the block
- """
+ def new_record(self):
+ """
+ Add a new record to the block. If autoCommit is set and a record is
+ currently pending it will be commited first.
+ """
- assert gDebug (4, "processing commit on block %s" % self.name, 1)
+ if not self._form.endEditing ():
+ return
- self.mode = 'commit'
+ # FIXME: GFForm.readonly and GFBlock.editable should be tested before
+ # enabling the menu item and the toolbar button. Once that is done, the
+ # tests here could be removed so trigger code can still insert new
+ # records while the user can't.
- self._resultSet.setRecord (self._precommitRecord)
+ if self._form.readonly:
+ self._form.alert_message(u_("Form is readonly"))
+ return
- if self._getMasterBlock () is None:
- self._dataSourceLink.postAll ()
+ if self.editable not in ('Y', 'new'):
+ event._form.alert_message(u_('Block does not allow insert'))
+ return
+ # Focus out
+ self.processTrigger ('PRE-FOCUSOUT')
+
+ if self.autoCommit and self._resultSet.current:
+ self._form.commit ()
+
+ self.processTrigger ('POST-FOCUSOUT')
+
+ self._resultSet.insertRecord(self._lastValues)
+ self._recordCount = self._resultSet.getRecordCount ()
+
+ # Focus in
+ self.processTrigger ('PRE-FOCUSIN')
+ self.processTrigger ('POST-FOCUSIN')
+
+ self._form.update_record_counter()
+ self._form.update_record_status()
+ self._form.dispatchEvent('gotoENTRY', object=self._form._currentEntry,
+ _form=self._form)
+ self._form.beginEditing()
+
# ---------------------------------------------------------------------------
- def finalizeCommit (self, commit):
+ def duplicateRecord (self, exclude = (), include = ()):
"""
- Called after the commit on the backend is through.
+ Create a new record and initialize it with field values from the record at
+ the current cursor position.
+
+ @param exclude: list of fields not to copy.
+ @param include: list of fields to copy. An empty list means to copy all
+ fields except primary key fields and rowid fields, which are never copied
+ anyway.
"""
- # Synchronize backend -> resultset -> UI
- if self._getMasterBlock () is None:
- self._dataSourceLink.requeryAll (commit)
+ # TODO: check if we need to do autoCommit and fire triggers here too
+ self._resultSet.duplicateRecord (exclude = exclude, include = include)
- # Our recordCount might have changed if records were deleted
- self._recordCount = self._resultSet.getRecordCount ()
- # If all records were deleted, create an empty new one.
- if not self._recordCount:
- self.newRecord ()
+ # ---------------------------------------------------------------------------
- self.mode = 'normal'
+ def deleteRecord (self):
+ """
+ Mark the current record for deletion. The acutal deletion will be done on
+ the next commit, call or update.
+ """
+ self._resultSet.current.delete ()
# ---------------------------------------------------------------------------
- def processClear (self):
+ def undeleteRecord (self):
"""
- Rollback the blocks pending changes (by calling a rollback of the backend)
- and finally create a new and empty result set. This method has no effect
- for detail-blocks.
+ Removes the deletion mark from the record
"""
- # Detail blocks cannot be cleared - they follow their master blindly.
- if self._getMasterBlock () is not None:
- return
+ self._resultSet.current.undelete ()
- if self._dataSourceLink._connection is not None:
- self._dataSourceLink._connection.rollback ()
- self._dataSourceLink.createEmptyResultSet ()
+ # ---------------------------------------------------------------------------
+ # Function and Update
+ # ---------------------------------------------------------------------------
+ def callFunction (self, name, parameters):
+ try:
+ # Remember the current record; the record pointer is not reliable between
+ # postAll and requeryAll!
+ current = self._resultSet.current
+ self._dataSourceLink.postAll ()
+
+ try:
+ res = current.call (name, parameters)
+ finally:
+ self._dataSourceLink.requeryAll (False)
+
+ finally:
+ self.__switch_record (0)
+
+ return res
+
# ---------------------------------------------------------------------------
- def processRollback (self, recovering = False, backendRollback = True):
- """
- Perform a rollback of all pending changes of the block.
- @param recovering: If False, the user requested a rollback and a new, empty
- result set will be created. If True, then a commit or such failed and we
- need to clean up (but not lose state information).
- @param backendRollback: If True, a rollback is performed on the backend
- connection, otherwise not.
- """
+ def updateCurrentRecordSet (self):
- # Detail blocks cannot be rolled back - they follow their master blindly.
- if self._getMasterBlock () is not None:
- return
+ try:
+ self._dataSourceLink.postAll ()
+ self._dataSourceLink.requeryAll (False)
- # If called from GFForm the connection's rollback () has been executed
- # already. But if called from a trigger code we do it here
- if backendRollback:
- if self._dataSourceLink._connection is not None:
- self._dataSourceLink._connection.rollback ()
+ finally:
+ self.__switch_record (0)
- if not recovering:
- self._dataSourceLink.createEmptyResultSet ()
-
# ---------------------------------------------------------------------------
+ # Query
+ # ---------------------------------------------------------------------------
def initQuery (self):
@@ -905,7 +854,7 @@
self._query2 = int (gConfigForms ("RememberLastQuery"))
self._queryValues = {}
self._queryValues.update (self._queryDefaults)
- self.switchRecord (0)
+ self.__switch_record (0)
# ---------------------------------------------------------------------------
@@ -914,14 +863,14 @@
self._query2 = 0
self._queryValues = {}
self._queryValues.update (self._lastQueryValues)
- self.switchRecord (0)
+ self.__switch_record (0)
# ---------------------------------------------------------------------------
def cancelQuery (self):
self.mode = 'normal'
- self.switchRecord (0)
+ self.__switch_record (0)
# ---------------------------------------------------------------------------
@@ -992,38 +941,147 @@
# ---------------------------------------------------------------------------
+ # Commit and Rollback
+ # ---------------------------------------------------------------------------
- def callFunction (self, name, parameters):
+ def commit (self):
+ """
+ Commit all pending changes of the form this block is bound to.
- try:
- # Remember the current record; the record pointer is not reliable between
- # postAll and requeryAll!
- current = self._resultSet.current
+ This method is depreciated. Please use form.commit () instead.
+ """
+
+ print "DEPRECIATION WARNING: the use of block.commit () is depreciated.", \
+ "Please use form.commit () instead."
+ self._form.commit ()
+
+ # ---------------------------------------------------------------------------
+
+ def processCommit (self):
+ """
+ Post all pending changes of the block
+ """
+
+ assert gDebug (4, "processing commit on block %s" % self.name, 1)
+
+ self.mode = 'commit'
+
+ self._resultSet.setRecord (self._precommitRecord)
+
+ if self._getMasterBlock () is None:
self._dataSourceLink.postAll ()
- try:
- res = current.call (name, parameters)
- finally:
- self._dataSourceLink.requeryAll (False)
+ # ---------------------------------------------------------------------------
- finally:
- self.switchRecord (0)
+ def finalizeCommit (self, commit):
+ """
+ Called after the commit on the backend is through.
+ """
- return res
+ # Synchronize backend -> resultset -> UI
+ if self._getMasterBlock () is None:
+ self._dataSourceLink.requeryAll (commit)
+ # Our recordCount might have changed if records were deleted
+ self._recordCount = self._resultSet.getRecordCount ()
+
+ # If all records were deleted, create an empty new one.
+ if not self._recordCount:
+ self.new_record()
+
+ self.mode = 'normal'
+
# ---------------------------------------------------------------------------
- def updateCurrentRecordSet (self):
+ def processClear (self):
+ """
+ Rollback the blocks pending changes (by calling a rollback of the backend)
+ and finally create a new and empty result set. This method has no effect
+ for detail-blocks.
+ """
- try:
- self._dataSourceLink.postAll ()
- self._dataSourceLink.requeryAll (False)
+ # Detail blocks cannot be cleared - they follow their master blindly.
+ if self._getMasterBlock () is not None:
+ return
- finally:
- self.switchRecord (0)
+ if self._dataSourceLink._connection is not None:
+ self._dataSourceLink._connection.rollback ()
+ self._dataSourceLink.createEmptyResultSet ()
# ---------------------------------------------------------------------------
+
+ def processRollback (self, recovering = False, backendRollback = True):
+ """
+ Perform a rollback of all pending changes of the block.
+ @param recovering: If False, the user requested a rollback and a new, empty
+ result set will be created. If True, then a commit or such failed and we
+ need to clean up (but not lose state information).
+ @param backendRollback: If True, a rollback is performed on the backend
+ connection, otherwise not.
+ """
+
+ # Detail blocks cannot be rolled back - they follow their master blindly.
+ if self._getMasterBlock () is not None:
+ return
+
+ # If called from GFForm the connection's rollback () has been executed
+ # already. But if called from a trigger code we do it here
+ if backendRollback:
+ if self._dataSourceLink._connection is not None:
+ self._dataSourceLink._connection.rollback ()
+
+ if not recovering:
+ self._dataSourceLink.createEmptyResultSet ()
+
+
+ # ---------------------------------------------------------------------------
+ # Helper Functions
+ # ---------------------------------------------------------------------------
+
+ def __switch_record (self, adjustment):
+ """
+ Moves the proper record into editing position
+ """
+
+ newRecord = self._resultSet.getRecordNumber ()
+ newRecordCount = self._resultSet.getRecordCount ()
+
+ self.__visibleStart += newRecord - self._currentRecord - adjustment
+
+ self.__visibleStart = min (self.__visibleStart, newRecord)
+ self.__visibleStart = max (self.__visibleStart, newRecord - self._rows + 1)
+ self.__visibleStart = max (self.__visibleStart, 0)
+
+ self._currentRecord = newRecord
+ self._recordCount = newRecordCount
+
+ for field in self._fieldList:
+ field._event_new_current_record ()
+
+ for entry in field._entryList:
+ # This loop is probably better somewhere else
+ entry.recalculate_visible (adjustment, self._currentRecord,
+ self._recordCount)
+
+ self._form.updateUIEntry (field)
+
+ # Ok, don't forgett the buttons here. Since they might be used within a
+ # block as well but don't have a corresponding field we need a seperate
+ # iteration.
+ for entry in self._entryList:
+ if entry._type == 'GFButton':
+ entry.recalculate_visible (adjustment, self._currentRecord,
+ self._recordCount)
+
+ self._form.refreshUIEvents ()
+
+ # Adjusting scrollbars
+ for sb in self._scrollbars:
+ sb.do_adjust_scrollbar (self.__visibleStart,
+ max (self._recordCount, self.__visibleStart + self._rows))
+
+ # ---------------------------------------------------------------------------
# Return the top level master block of this block
# ---------------------------------------------------------------------------
@@ -1055,52 +1113,10 @@
return None
- # ---------------------------------------------------------------------------
- # Get a sequence of dictionaries from the current resultSet
- # ---------------------------------------------------------------------------
-
- def get_data(self, fieldnames):
- """
- Build a list of dictionaries of the current resultset using the fields
- defined by fieldnames.
-
- @param fieldnames: list of fieldnames to export per record
- @returns: list of dictionaries (one per record)
- """
-
- result = []
- if not fieldnames:
- fields = self._fieldMap.values()
- else:
- fields = [self._fieldMap[fld] for fld in fieldnames]
-
- for r in self._resultSet:
- add = {}
- for field in fields:
- fname = field.field
- if hasattr(field, 'fk_source'):
- value = field._allowedValues.get(r[fname])
- else:
- value = r[fname]
-
- add[fname] = value
-
- result.append(add)
-
- return result
-
-
# ===========================================================================
# Trigger Namespace properties
# ===========================================================================
- def trigger_get_data(self, fields):
-
- return self.get_data(fields)
-
- # ---------------------------------------------------------------------------
-
-
def triggerSetAutoCommit (self, value):
self.autoCommit = bool (value)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8649 - in trunk/gnue-forms/src: . GFObjects,
reinhard <=