[orm-devel] Change request for dbclass
Michael Watkins
orm-devel@mailman.tux4web.de
Mon, 17 Feb 2003 14:59:55 -0800
I have a request for a minor change to dbclass.py to make it compatible
with a Python based web application framework called Quixote (
http://www.mems-exchange.org/software/quixote/ check it out, it is very useful)
around line 200, place the following test:
# MW next line is a patch to deal with Quixote.
if name == "_p_oid" : return None
Quixote's forms handler has some useful widgets that make for quick and
easy work with select lists. One aspect of the handler interrogates the
object to see if it has an attribute _p_oid (this is a ZODB Zope Object DB
attribute).
Better yet, lets make dbclass a little more generic so that it doesn't fail
when code that isn't aware of ORM attempts to call an attribute that starts
with '_' - that is the real source of the issue here -
dbclass.__getattr__ needs a little clean up.
Look through the original code in the except block and let me know what you
think.
def __getattr__(self, name):
"""
The __getattr__ method is overwriten to call each column's get
method when an attribute is requested. Attributes that start
with a _ are ignored.
"""
# MW next line is a patch to deal with Quixote.
if name == "_p_oid" : return None #self.__dict__['_oid']
if name[0] == "_" : return self.__dict__[name]
try:
column = self._data[name]
except KeyError:
if self.columns.has_key(name):
return None
else:
return self.__dict__[name]
return column.get()