Author: echuck
Date: 2005-03-22 21:42:33 -0700 (Tue, 22 Mar 2005)
New Revision: 2221
Modified:
Webware/trunk/MiddleKit/Run/MiddleObject.py
Log:
Added isNew() convenience method.
Enhanced valueForKey() to access ordinary Python attributes and methods even if they aren't declared in the object model.
Modified: Webware/trunk/MiddleKit/Run/MiddleObject.py
===================================================================
--- Webware/trunk/MiddleKit/Run/MiddleObject.py 2005-03-23 04:36:51 UTC (rev 2220)
+++ Webware/trunk/MiddleKit/Run/MiddleObject.py 2005-03-23 04:42:33 UTC (rev 2221)
@@ -139,7 +139,14 @@
def isInStore(self):
return self._mk_inStore
+ def isNew(self):
+ """
+ Returns true if the object was newly created (whether added to the store or not). Objects
+ fetched from the database will return false.
+ """
+ return self._mk_serialNum<1
+
## Keys ##
def key(self):
@@ -316,13 +323,21 @@
the test suites use this instead of directly invoking the "get"
methods.
- If the attribute is not found, the default argument is returned
+ If the attribute is not found, this method will look for any
+ Python attribute or method that matches.
+
+ If a value is still not found, the default argument is returned
if specified, otherwise LookupError is raised with the attrName.
"""
attr = self.klass().lookupAttr(attrName, None)
if attr:
return self.valueForAttr(attr, default)
else:
+ value = getattr(self, attrName, NoDefault)
+ if value is not NoDefault:
+ if callable(value):
+ value = value()
+ return value
if default is NoDefault:
raise LookupError, attrName
else:
|