dabo Commit
Revision 4481
Date: 2008-08-28 14:15:50 -0700 (Thu, 28 Aug 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/4481

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

Log:
Improved VirtualFields by adding the option to set a given VirtualField
to a dict instead of a function. Currently, this dict has one required
key, "func", that stores the function object, and an optional key,
"requery_children", that determines whether or not child records are
requeried before the virtual field function is run.

Changed default behavior to *not run* the child requeries, as this 
was a performance hog for an uncommon case. If your VirtualFields
function requires that child records have been requeried before 
running, then you can either requery them inside the function itself,
or define the VirtualFields like the following:

old:
  self.VirtualFields["myfield"] = myFunc

new:
  self.VirtualFields["myfield"] = {"func": myFunc, "requery_children": True}

TODO: Note this in the docstring.
 


Diff:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2008-08-28 20:55:05 UTC (rev 4480)
+++ trunk/dabo/db/dCursorMixin.py       2008-08-28 21:15:50 UTC (rev 4481)
@@ -817,22 +817,28 @@
                                return rec[fld]
                        else:
                                if self.VirtualFields.has_key(fld):
+                                       vf = self.VirtualFields[fld]
+                                       if not isinstance(vf, dict):
+                                               vf = {"func": vf}
+
+                                       requery_children = 
(vf.get("requery_children", False) and bool(_rowChangeCallback))
+
                                        # Move to specified row if necessary, 
and then call the VirtualFields
                                        # function, which expects to be on the 
correct row.
-                                       if not _rowChangeCallback:
-                                               # We aren't being called by a 
bizobj, so there aren't child bizobjs,
-                                               # so the VirtualFields won't be 
reliant on childen, so this should work.
+                                       if not requery_children:
+                                               # The VirtualFields 
'requery_children' key is False, or
+                                               # we aren't being called by a 
bizobj, so there aren't child bizobjs.
                                                _oldrow = self.RowNumber
                                                self.RowNumber = row
-                                               ret = self.VirtualFields[fld]()
+                                               ret = vf["func"]()
                                                self.RowNumber = _oldrow
                                                return ret
                                        else:
-                                               # A bizobj called us, so we 
need to request a row change and requery
-                                               # of any child bizobjs as 
necessary, before executing the virtual
-                                               # field function.
+                                               # The VirtualFields 
definition's 'requery_children' key is True, so 
+                                               # we need to request a row 
change and requery of any child bizobjs 
+                                               # as necessary, before 
executing the virtual field function.
                                                _rowChangeCallback(row)
-                                               return self.VirtualFields[fld]()
+                                               return vf["func"]()
                                else:
                                        raise 
dException.FieldNotFoundException, "%s '%s' %s" % (
                                                        _("Field"), fld, 
_("does not exist in the data set"))




_______________________________________________
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