dabo Commit
Revision 6326
Date: 2011-01-18 15:45:52 -0800 (Tue, 18 Jan 2011)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6326

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

Log:
Added the ability to specify which record to setFieldVal() on, by sending the pk
of the row to set. 


Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2011-01-18 03:49:02 UTC (rev 6325)
+++ trunk/dabo/biz/dBizobj.py   2011-01-18 23:45:52 UTC (rev 6326)
@@ -1649,20 +1649,20 @@
                return ret
 
 
-       def setFieldVal(self, fld, val, row=None):
+       def setFieldVal(self, fld, val, row=None, pk=None):
                """Set the value of the specified field in the current or 
specified row."""
                cursor = self._CurrentCursor
                if cursor is None:
                        return
                try:
-                       changed = cursor.setFieldVal(fld, val, row)
+                       changed = cursor.setFieldVal(fld, val, row, pk)
                except (dException.NoRecordsException, 
dException.RowNotFoundException):
                        return False
                if changed:
                        self.afterSetFieldVal(fld, row)
 
 
-       def setFieldVals(self, valDict=None, row=None, **kwargs):
+       def setFieldVals(self, valDict=None, row=None, pk=None, **kwargs):
                """Allows you to 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.
                """
@@ -1671,7 +1671,7 @@
                else:
                        valDict.update(kwargs)
                for fld, val in valDict.items():
-                       self.setFieldVal(fld, val, row)
+                       self.setFieldVal(fld, val, row, pk)
 
        setValues = setFieldVals  ## deprecate setValues in future version
 

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2011-01-18 03:49:02 UTC (rev 6325)
+++ trunk/dabo/db/dCursorMixin.py       2011-01-18 23:45:52 UTC (rev 6326)
@@ -931,29 +931,34 @@
                return True
 
 
-       def setFieldVals(self, valDict, row=None):
+       def setFieldVals(self, valDict, row=None, pk=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)
+                       self.setFieldVal(fld, val, row, pk)
        setValuesByDict = setFieldVals  ## deprecate setValuesByDict in future
 
 
-       def setFieldVal(self, fld, val, row=None):
+       def setFieldVal(self, fld, val, row=None, pk=None):
                """Set the value of the specified field."""
                if self.RowCount <= 0:
                        raise dException.NoRecordsException(
                                        _("No records in dataset '%s'.") % 
self.Table)
-               if row is None:
+
+               rec = None
+               if pk is not None:
+                       row, rec = self._getRecordByPk(pk)
+               elif row is None:
                        row = self.RowNumber
 
-               try:
-                       rec = self._records[row]
-               except IndexError:
-                       cnt = len(self._records)
-                       raise dException.RowNotFoundException(
-                                       _("Row #%(row)s requested, but the data 
set has only %(cnt)s row(s),") % locals())
+               if not rec:
+                       try:
+                               rec = self._records[row]
+                       except IndexError:
+                               cnt = len(self._records)
+                               raise dException.RowNotFoundException(
+                                               _("Row #%(row)s requested, but 
the data set has only %(cnt)s row(s),") % locals())
                valid_pk = self._hasValidKeyField()
                keyField = self.KeyField
                if fld not in rec:



_______________________________________________
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