Changed to_dict to call all callable values when their key is in field_names.
authorLennard de Rijk <ljvderijk@gmail.com>
Thu, 13 Aug 2009 10:23:31 -0700
changeset 2767 4011d44ba0b6
parent 2766 93e4745ebdbd
child 2768 97a1569b2743
Changed to_dict to call all callable values when their key is in field_names. This is useful for instance when exporting role instances and you want to export document_name.
app/soc/models/base.py
--- a/app/soc/models/base.py	Wed Aug 12 15:44:18 2009 -0700
+++ b/app/soc/models/base.py	Thu Aug 13 10:23:31 2009 -0700
@@ -22,6 +22,7 @@
 
 __authors__ = [
   '"Todd Larsen" <tlarsen@google.com>',
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
 ]
 
 
@@ -68,12 +69,12 @@
       if not hasattr(self, key):
         continue
 
-      result[key] = getattr(self, key)
+      value = getattr(self, key)
 
-    if hasattr(self, 'name'):
-      name_prop = getattr(self, 'name')
-      if callable(name_prop):
-        result['name'] = name_prop()
+      if callable(value):
+        value = value()
+
+      result[key] = value
 
     return result