Mercurial > kallithea
comparison rhodecode/model/db.py @ 1948:4582e6b9e2f6 beta
get_dict function garden
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 24 Jan 2012 20:02:21 +0200 |
parents | 50e32940e464 |
children | 4ae17f819ee8 |
comparison
equal
deleted
inserted
replaced
1946:72e160dff58e | 1948:4582e6b9e2f6 |
---|---|
92 @classmethod | 92 @classmethod |
93 def _get_keys(cls): | 93 def _get_keys(cls): |
94 """return column names for this model """ | 94 """return column names for this model """ |
95 return class_mapper(cls).c.keys() | 95 return class_mapper(cls).c.keys() |
96 | 96 |
97 def get_dict(self, serialized=False): | 97 def get_dict(self): |
98 """ | 98 """ |
99 return dict with keys and values corresponding | 99 return dict with keys and values corresponding |
100 to this model data | 100 to this model data """ |
101 """ | |
102 | 101 |
103 d = {} | 102 d = {} |
104 for k in self._get_keys(): | 103 for k in self._get_keys(): |
105 d[k] = getattr(self, k) | 104 d[k] = getattr(self, k) |
106 | 105 |
107 # also use __json__() if present to get additional fields | 106 # also use __json__() if present to get additional fields |
108 if hasattr(self, '__json__'): | 107 for k, val in getattr(self, '__json__', lambda: {})().iteritems(): |
109 for k, val in self.__json__().iteritems(): | 108 d[k] = val |
110 d[k] = val | |
111 return d | 109 return d |
112 | 110 |
113 def get_appstruct(self): | 111 def get_appstruct(self): |
114 """return list with keys and values tupples corresponding | 112 """return list with keys and values tupples corresponding |
115 to this model data """ | 113 to this model data """ |