app/soc/models/base.py
changeset 1809 66aec0241d61
parent 1728 0bda51fe91bf
child 1845 2651cb3979db
--- a/app/soc/models/base.py	Thu Mar 12 14:16:55 2009 +0000
+++ b/app/soc/models/base.py	Thu Mar 12 21:36:39 2009 +0000
@@ -47,18 +47,27 @@
   """
 
   _fields_cache = None
+  DICT_TYPES = (db.StringProperty, db.IntegerProperty)
 
-  def toDict(self):
-    """Returns a dict with all StringProperty values of this entity.
+  def toDict(self, field_names=None):
+    """Returns a dict with all specified values of this entity.
+
+    Args:
+      field_names: the fields that should be included, defaults to
+        all fields that are of a type that is in DICT_TYPES.
     """
 
     result = {}
     props = self.properties()
 
+    if not field_names:
+      field_names = [i for i in props.keys() if isinstance(i, self.DICT_TYPES)]
+
     for key, value in props.iteritems():
-      # Skip everything but StringProperties and IntegerProperties
-      if not isinstance(value, (db.StringProperty, db.IntegerProperty)):
+      # Skip everything that is not valid
+      if key not in field_names:
         continue
+
       result[key] = getattr(self, key)
 
     if hasattr(self, 'name'):