dabo Commit
Revision 6234
Date: 2010-12-03 11:36:25 -0800 (Fri, 03 Dec 2010)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6234

Changed:
U   trunk/dabo/biz/dBizobj.py
U   trunk/dabo/db/dCursorMixin.py

Log:
Clear the bizobj's cursorRecord when DataStructure and VirtualFields are set, 
as 
well as in requery().

Added AttributeError check around the del() call.

Changed afterSetFieldVal() to only fire if the field value had actually changed,
and enhanced dCursorMixin to report that.

biz.setFieldVals() now calls biz.setFieldVal() for each field, so that the 
afterSetFieldVal() hook will be fired when the field changes.



Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2010-12-03 00:18:51 UTC (rev 6233)
+++ trunk/dabo/biz/dBizobj.py   2010-12-03 19:36:25 UTC (rev 6234)
@@ -1024,8 +1024,15 @@
                        raise uiException
 
                if self.DataStructure != oldDataStructure:
-                       ## The Record object must be reinstantiated to reflect 
the new structure:
+                       self._clearCursorRecord()
+
+
+       def _clearCursorRecord(self):
+               ## The Record object must be reinstantiated to reflect the new 
structure:
+               try:
                        del(self._cursorRecord)
+               except AttributeError:
+                       pass
 
 
        def setChildLinkFilter(self):
@@ -1640,10 +1647,11 @@
                if cursor is None:
                        return
                try:
-                       cursor.setFieldVal(fld, val, row)
+                       changed = cursor.setFieldVal(fld, val, row)
                except (dException.NoRecordsException, 
dException.RowNotFoundException):
                        return False
-               self.afterSetFieldVal(fld, row)
+               if changed:
+                       self.afterSetFieldVal(fld, row)
 
 
        def setFieldVals(self, valDict=None, row=None, **kwargs):
@@ -1654,13 +1662,8 @@
                        valDict = kwargs
                else:
                        valDict.update(kwargs)
-               cursor = self._CurrentCursor
-               if cursor is not None:
-                       try:
-                               ret = cursor.setValuesByDict(valDict, row)
-                       except dException.NoRecordsException:
-                               ret = False
-               return ret
+               for fld, val in valDict.items():
+                       self.setFieldVal(fld, val, row)
 
        setValues = setFieldVals  ## deprecate setValues in future version
 
@@ -2067,7 +2070,7 @@
 
 
        def afterSetFieldVal(self, fld, row):
-               """Hook method called after a field's value has been changed.
+               """Hook method called after a field's value has been set.
 
                Your hook method needs to accept two arguments:
                                -> fld : The name of the changed field.
@@ -2075,6 +2078,9 @@
 
                If row is None, this is the common case of the change happening
                in the current row.
+
+               Note that this hook will only fire if the new field value is 
different
+               from the old.
                """
 
 
@@ -2206,6 +2212,7 @@
                for key, cursor in self.__cursors.items():
                        cursor.DataStructure = val
                self._dataStructure = val
+               self._clearCursorRecord()
 
 
        def _getDefaultValues(self):
@@ -2226,6 +2233,7 @@
        def _setVirtualFields(self, val):
                self._virtualFields = val
                self._syncWithCursors()
+               self._clearCursorRecord()
 
 
        def _getEncoding(self):

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2010-12-03 00:18:51 UTC (rev 6233)
+++ trunk/dabo/db/dCursorMixin.py       2010-12-03 19:36:25 UTC (rev 6234)
@@ -931,12 +931,13 @@
                return True
 
 
-       def setValuesByDict(self, valDict, row=None):
+       def setFieldVals(self, valDict, row=None):
                """Set the value for multiple fields with one call by passing a 
dict containing
                the field names as keys, and the new values as values.
                """
                for fld, val in valDict.items():
                        self.setFieldVal(fld, val, row)
+       setValuesByDict = setFieldVals  ## deprecate setValuesByDict in future
 
 
        def setFieldVal(self, fld, val, row=None):
@@ -1017,7 +1018,9 @@
                # If the new value is different from the current value, change 
it and also
                # update the mementos if necessary.
                old_val = rec[fld]
-               if old_val != val:
+               if old_val == val:
+                       return False
+               else:
                        if valid_pk:
                                if fld == keyField:
                                        # Changing the key field value, need to 
key the mementos on the new
@@ -1067,8 +1070,9 @@
                                dabo.log.info("Field value changed, but the 
memento"
                                                " can't be saved, because there 
is no valid KeyField.")
 
-                       # Finally, save the new value to the field:
+                       # Finally, save the new value to the field and signify 
that the field was changed:
                        rec[fld] = val
+                       return True
 
 
        def getRecordStatus(self, row=None, pk=None):



_______________________________________________
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]

Reply via email to