[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7893 - trunk/gnue-common/src/datasources/drivers/Base
From: |
reinhard |
Subject: |
[gnue] r7893 - trunk/gnue-common/src/datasources/drivers/Base |
Date: |
Fri, 9 Sep 2005 10:33:06 -0500 (CDT) |
Author: reinhard
Date: 2005-09-09 10:33:04 -0500 (Fri, 09 Sep 2005)
New Revision: 7893
Modified:
trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
Log:
Added support for new onRecordInserted event. Added record parameter to all
record level events.
Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-09-09
11:13:27 UTC (rev 7892)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-09-09
15:33:04 UTC (rev 7893)
@@ -169,13 +169,15 @@
# requeried again after the following commit
self.__requeryStatus = None
+ # While this is true, changes don't mark the record as dirty.
+ self.__initializing = True
+
if self.__initialData:
# Existing record:
# Set the current state of all fields as given in the parameter
self.__fields = self.__initialData.copy ()
- if self.__eventController is not None:
- self.__eventController.dispatchEvent ('dsRecordLoaded')
+ self.__dispatchEvent ('dsRecordLoaded')
else:
@@ -199,9 +201,14 @@
# 4. Get default values from DataSource (includes link to master).
for (fieldname, value) in defaultData.items ():
- self.__setField (fieldname, value)
+ self [fieldname] = value
+ # 5. Notify event listener about new record
+ self.__dispatchEvent ('dsRecordInserted')
+ self.__initializing = False
+
+
# ---------------------------------------------------------------------------
# String representation
# ---------------------------------------------------------------------------
@@ -246,15 +253,15 @@
"""
if fieldname in self.__boundFields and self.__readonly:
raise Exceptions.ReadOnlyModifyError
- self.__setField (fieldname, value)
- if fieldname in self.__boundFields:
+ self.__fields [fieldname] = value
+ self.__modifiedFlags [fieldname] = True
+ if not self.__initializing and fieldname in self.__boundFields:
if self.__status in ['empty', 'clean']:
if self.__status == 'empty':
self.__status = 'inserted'
elif self.__status == 'clean':
self.__status = 'modified'
- if self.__eventController is not None:
- self.__eventController.dispatchEvent ('dsRecordTouched')
+ self.__dispatchEvent ('dsRecordTouched')
# ---------------------------------------------------------------------------
@@ -307,21 +314,6 @@
# ---------------------------------------------------------------------------
- # Set a field and mark it as dirty, leaving the record state unchanged
- # ---------------------------------------------------------------------------
-
- def __setField (self, fieldname, value):
-
- # Calling this function directly (instead of __setitem__) causes the field
- # to be marked as dirty, but the complete record remains unchanged. This is
- # useful to initialize a new record: the record will still be regarded as
- # "empty", but the field will be included in any following insert
- # statement.
- self.__fields [fieldname] = value
- self.__modifiedFlags [fieldname] = True
-
-
- # ---------------------------------------------------------------------------
# Find out if a field is modified
# ---------------------------------------------------------------------------
@@ -605,15 +597,14 @@
status = self.__status
# Call the hooks for commit-level hooks
- if self.__eventController is not None:
- # A trigger code could change the status from empty/inserted/modified to
- # deleted. In that case, both triggers would be called.
- if self.__status in ['empty', 'inserted']:
- self.__eventController.dispatchEvent ('dsCommitInsert')
- if self.__status == 'modified':
- self.__eventController.dispatchEvent ('dsCommitUpdate')
- if self.__status == 'deleted':
- self.__eventController.dispatchEvent ('dsCommitDelete')
+ # A trigger code could change the status from empty/inserted/modified to
+ # deleted. In that case, both triggers would be called.
+ if self.__status in ['empty', 'inserted']:
+ self.__dispatchEvent ('dsCommitInsert')
+ if self.__status == 'modified':
+ self.__dispatchEvent ('dsCommitUpdate')
+ if self.__status == 'deleted':
+ self.__dispatchEvent ('dsCommitDelete')
# Check for empty primary key and set with the sequence value if so
if self.__status in ['empty', 'inserted']:
@@ -735,6 +726,15 @@
# ---------------------------------------------------------------------------
+ # Dispatch an event
+ # ---------------------------------------------------------------------------
+
+ def __dispatchEvent (self, event):
+ if self.__eventController is not None:
+ self.__eventController.dispatchEvent (event, record = self)
+
+
+ # ---------------------------------------------------------------------------
# Depreciated methods (replaced by dictionary functions)
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7893 - trunk/gnue-common/src/datasources/drivers/Base,
reinhard <=