Mercurial > kallithea
diff rhodecode/model/db.py @ 1758:a87aa385f21c beta
fixed repo_create permission by adding missing commit statements
- added few tests for checking permission in UserModel
- added __json__() into get_dict() to fetch from it hybrid_properties and any additional custom properties
- code garden
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 06 Dec 2011 04:06:01 +0200 |
parents | 2aa7f454204e |
children | 6c86c987cf93 |
line wrap: on
line diff
--- a/rhodecode/model/db.py Tue Dec 06 01:18:27 2011 +0200 +++ b/rhodecode/model/db.py Tue Dec 06 04:06:01 2011 +0200 @@ -82,8 +82,8 @@ return json.JSONEncoder.default(self, obj) class BaseModel(object): - """Base Model for all classess - + """ + Base Model for all classess """ @classmethod @@ -91,13 +91,20 @@ """return column names for this model """ return class_mapper(cls).c.keys() - def get_dict(self): - """return dict with keys and values corresponding - to this model data """ + def get_dict(self, serialized=False): + """ + return dict with keys and values corresponding + to this model data + """ d = {} for k in self._get_keys(): d[k] = getattr(self, k) + + # also use __json__() if present to get additional fields + if hasattr(self, '__json__'): + for k,val in self.__json__().iteritems(): + d[k] = val return d def get_appstruct(self): @@ -350,6 +357,11 @@ log.debug('updated user %s lastlogin', self.username) + def __json__(self): + return dict(email=self.email, + full_name=self.full_name) + + class UserLog(Base, BaseModel): __tablename__ = 'user_logs' __table_args__ = {'extend_existing':True}