app/soc/models/base.py
changeset 1809 66aec0241d61
parent 1728 0bda51fe91bf
child 1845 2651cb3979db
equal deleted inserted replaced
1808:f6ec0f486247 1809:66aec0241d61
    45   because any actual Form code refers to these new names, so they are should
    45   because any actual Form code refers to these new names, so they are should
    46   be familiar to view creators.  
    46   be familiar to view creators.  
    47   """
    47   """
    48 
    48 
    49   _fields_cache = None
    49   _fields_cache = None
       
    50   DICT_TYPES = (db.StringProperty, db.IntegerProperty)
    50 
    51 
    51   def toDict(self):
    52   def toDict(self, field_names=None):
    52     """Returns a dict with all StringProperty values of this entity.
    53     """Returns a dict with all specified values of this entity.
       
    54 
       
    55     Args:
       
    56       field_names: the fields that should be included, defaults to
       
    57         all fields that are of a type that is in DICT_TYPES.
    53     """
    58     """
    54 
    59 
    55     result = {}
    60     result = {}
    56     props = self.properties()
    61     props = self.properties()
    57 
    62 
       
    63     if not field_names:
       
    64       field_names = [i for i in props.keys() if isinstance(i, self.DICT_TYPES)]
       
    65 
    58     for key, value in props.iteritems():
    66     for key, value in props.iteritems():
    59       # Skip everything but StringProperties and IntegerProperties
    67       # Skip everything that is not valid
    60       if not isinstance(value, (db.StringProperty, db.IntegerProperty)):
    68       if key not in field_names:
    61         continue
    69         continue
       
    70 
    62       result[key] = getattr(self, key)
    71       result[key] = getattr(self, key)
    63 
    72 
    64     if hasattr(self, 'name'):
    73     if hasattr(self, 'name'):
    65       name_prop = getattr(self, 'name')
    74       name_prop = getattr(self, 'name')
    66       if callable(name_prop):
    75       if callable(name_prop):