diff -r f6ec0f486247 -r 66aec0241d61 app/soc/models/base.py --- 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'):