dabo Commit
Revision 6233
Date: 2010-12-02 16:18:51 -0800 (Thu, 02 Dec 2010)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6233
Changed:
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/db/__init__.py
U trunk/dabo/db/dCursorMixin.py
Log:
Refactored CursorRecord out of dabo.db.dCursorMixin into dabo.db. Now
both dCursorMixin and dBizobj can use the class to instantiate their
own Record instances. This effectively means that assigning to
biz.Record.field no longer calls cur.setFieldVal() directly but
instead calls biz.setFieldVal(), allowing easy interference to be
run by appdev code.
Added biz.afterSetFieldVal() hook method.
Refactored biz.setFieldVal() to do away with the ret value, as dCursor
doesn't return anything but None anyway.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2010-12-01 13:18:34 UTC (rev 6232)
+++ trunk/dabo/biz/dBizobj.py 2010-12-03 00:18:51 UTC (rev 6233)
@@ -989,6 +989,8 @@
except dException.NoRecordsException:
currPK = None
+ oldDataStructure = self.DataStructure
+
# run the requery
uiException = None
cursor = self._CurrentCursor
@@ -1015,11 +1017,17 @@
self.requeryAllChildren()
except dException.NoRecordsException:
pass
+
self.afterRequery()
+
if uiException:
raise uiException
+ if self.DataStructure != oldDataStructure:
+ ## The Record object must be reinstantiated to reflect
the new structure:
+ del(self._cursorRecord)
+
def setChildLinkFilter(self):
""" If this is a child bizobj, its record set is dependent on
its parent's
current PK value. This will add the appropriate WHERE clause to
@@ -1629,12 +1637,13 @@
def setFieldVal(self, fld, val, row=None):
"""Set the value of the specified field in the current or
specified row."""
cursor = self._CurrentCursor
- if cursor is not None:
- try:
- ret = cursor.setFieldVal(fld, val, row)
- except (dException.NoRecordsException,
dException.RowNotFoundException):
- ret = False
- return ret
+ if cursor is None:
+ return
+ try:
+ cursor.setFieldVal(fld, val, row)
+ except (dException.NoRecordsException,
dException.RowNotFoundException):
+ return False
+ self.afterSetFieldVal(fld, row)
def setFieldVals(self, valDict=None, row=None, **kwargs):
@@ -1972,7 +1981,7 @@
- def _makeHookMethod(name, action, mainDoc=None, additionalDoc=None):
+ def _makeHookMethod(name, action, mainDoc=None, additionalDoc=None):
mode = name[:5]
if mode == "befor":
mode = "before"
@@ -2057,6 +2066,18 @@
cursor."""
+ def afterSetFieldVal(self, fld, row):
+ """Hook method called after a field's value has been changed.
+
+ Your hook method needs to accept two arguments:
+ -> fld : The name of the changed field.
+ -> row : The RowNumber of the changed field.
+
+ If row is None, this is the common case of the change happening
+ in the current row.
+ """
+
+
def _syncWithCursors(self):
"""Many bizobj properties need to be passed through to the
cursors
that provide it with data connectivity. This method ensures
that all
@@ -2322,7 +2343,11 @@
def _getRecord(self):
- return self._CurrentCursor.Record
+ try:
+ ret = self._cursorRecord
+ except AttributeError:
+ ret = self._cursorRecord = dabo.db._getRecord(self)
+ return ret
def _getRemoteProxy(self):
Modified: trunk/dabo/db/__init__.py
===================================================================
--- trunk/dabo/db/__init__.py 2010-12-01 13:18:34 UTC (rev 6232)
+++ trunk/dabo/db/__init__.py 2010-12-03 00:18:51 UTC (rev 6233)
@@ -85,3 +85,42 @@
return dConnection(*args, **kwargs)
+def _getRecord(self):
+ ### Used by dCursorMixin *and* dBizobj.
+ class CursorRecord(object):
+ def __init__(self, _cursor):
+ self._cursor = _cursor
+ super(CursorRecord, self).__init__()
+
+ def __getattr__(self, att):
+ return self._cursor.getFieldVal(att)
+
+ def __setattr__(self, att, val):
+ if att in ("_cursor"):
+ super(CursorRecord, self).__setattr__(att, val)
+ else:
+ self._cursor.setFieldVal(att, val)
+
+ def __getitem__(self, key):
+ return self.__getattr__(key)
+
+ def __setitem__(self, key, val):
+ return self.__setattr__(key, val)
+
+ ## The rest of this block adds a property to the Record object
+ ## for each field, the sole purpose being to have the field
+ ## names appear in the command window intellisense dropdown.
+ def getFieldProp(field_name):
+ def fget(self):
+ return self._cursor.getFieldVal(field_name)
+ def fset(self, val):
+ self._cursor.setFieldVal(field_name, val)
+ return property(fget, fset)
+
+ field_aliases = [ds[0] for ds in self.DataStructure]
+ field_aliases.extend(self.VirtualFields.keys())
+ for field_alias in field_aliases:
+ setattr(CursorRecord, field_alias, getFieldProp(field_alias))
+ return CursorRecord(self)
+
+
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2010-12-01 13:18:34 UTC (rev 6232)
+++ trunk/dabo/db/dCursorMixin.py 2010-12-03 00:18:51 UTC (rev 6233)
@@ -2655,41 +2655,7 @@
try:
ret = self._cursorRecord
except AttributeError:
- class CursorRecord(object):
- def __init__(self, _cursor):
- self._cursor = _cursor
- super(CursorRecord, self).__init__()
-
- def __getattr__(self, att):
- return self._cursor.getFieldVal(att)
-
- def __setattr__(self, att, val):
- if att in ("_cursor"):
- super(CursorRecord,
self).__setattr__(att, val)
- else:
- self._cursor.setFieldVal(att,
val)
-
- def __getitem__(self, key):
- return self.__getattr__(key)
-
- def __setitem__(self, key, val):
- return self.__setattr__(key, val)
-
- ## The rest of this block add a property to the Record
object
- ## for each field, the sole purpose being to have the
field
- ## names appear in the command window intellisense
dropdown.
- def getFieldProp(field_name):
- def fget(self):
- return
self._cursor.getFieldVal(field_name)
- def fset(self, val):
- self._cursor.setFieldVal(field_name,
val)
- return property(fget, fset)
-
- field_aliases = [ds[0] for ds in self.DataStructure]
- field_aliases.extend(self.VirtualFields.keys())
- for field_alias in field_aliases:
- setattr(CursorRecord, field_alias,
getFieldProp(field_alias))
- ret = self._cursorRecord = CursorRecord(self)
+ ret = self._cursorRecord = dabo.db._getRecord(self)
return ret
_______________________________________________
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]