dabo Commit
Revision 5410
Date: 2009-09-22 16:19:36 -0700 (Tue, 22 Sep 2009)
Author: Paul
Trac: http://trac.dabodev.com/changeset/5410

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

Log:
Changed CursorRecord to inherit from dict instead of object, giving the ability
to reference field values using a mapping interface, without losing the 
object interface that existed before.

self.Record.field
   and
self.Record[field]

do the same thing. I wanted this for string formatting like:

csz = "%(city)s, %(state)s  %(zip)" % self.Record



Diff:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2009-09-22 21:55:18 UTC (rev 5409)
+++ trunk/dabo/db/dCursorMixin.py       2009-09-22 23:19:36 UTC (rev 5410)
@@ -2528,7 +2528,7 @@
                try:
                        ret = self._cursorRecord
                except AttributeError:
-                       class CursorRecord(object):
+                       class CursorRecord(dict):
                                def __init__(self):
                                        self.cursor = None
                                        super(CursorRecord, self).__init__()
@@ -2542,6 +2542,12 @@
                                        else:
                                                self.cursor.setFieldVal(att, 
val)
 
+                               def __getitem__(self, key):
+                                       return self.__getattr__(key)
+
+                               def __setitem__(self, key, val):
+                                       return self.__setattr__(key, val)
+
                        ret = self._cursorRecord = CursorRecord()
                        self._cursorRecord.cursor = 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]

Reply via email to