Mercurial > kallithea
comparison rhodecode/model/db.py @ 2508:43cb5b6047fd beta
Added functions for getting API data to repo and user models
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 26 Jun 2012 02:21:06 +0200 |
parents | 7e3e9d0c5575 |
children | 9059b2d91303 |
comparison
equal
deleted
inserted
replaced
2507:374693af2849 | 2508:43cb5b6047fd |
---|---|
425 """Update user lastlogin""" | 425 """Update user lastlogin""" |
426 self.last_login = datetime.datetime.now() | 426 self.last_login = datetime.datetime.now() |
427 Session.add(self) | 427 Session.add(self) |
428 log.debug('updated user %s lastlogin' % self.username) | 428 log.debug('updated user %s lastlogin' % self.username) |
429 | 429 |
430 def get_api_data(self): | |
431 """ | |
432 Common function for generating user related data for API | |
433 """ | |
434 user = self | |
435 data = dict( | |
436 id=user.user_id, | |
437 username=user.username, | |
438 api_key=user.api_key, | |
439 firstname=user.name, | |
440 lastname=user.lastname, | |
441 email=user.email, | |
442 emails=user.emails, | |
443 active=user.active, | |
444 admin=user.admin, | |
445 ldap_dn=user.ldap_dn, | |
446 last_login=user.last_login, | |
447 ) | |
448 return data | |
449 | |
430 def __json__(self): | 450 def __json__(self): |
431 return dict( | 451 return dict( |
432 user_id=self.user_id, | 452 user_id=self.user_id, |
433 first_name=self.name, | 453 first_name=self.name, |
434 last_name=self.lastname, | 454 last_name=self.lastname, |
731 :param repo_name: | 751 :param repo_name: |
732 """ | 752 """ |
733 from rhodecode.lib.utils import is_valid_repo | 753 from rhodecode.lib.utils import is_valid_repo |
734 | 754 |
735 return is_valid_repo(repo_name, cls.base_path()) | 755 return is_valid_repo(repo_name, cls.base_path()) |
756 | |
757 def get_api_data(self): | |
758 """ | |
759 Common function for generating repo api data | |
760 | |
761 """ | |
762 repo = self | |
763 data = dict( | |
764 id=repo.repo_id, | |
765 repo_name=repo.repo_name, | |
766 repo_type=repo.repo_type, | |
767 clone_uri=repo.clone_uri, | |
768 private=repo.private, | |
769 created_on=repo.created_on, | |
770 description=repo.description, | |
771 landing_rev=repo.landing_rev, | |
772 owner=repo.user.username, | |
773 fork_of=repo.fork.repo_name if repo.fork else None | |
774 ) | |
775 | |
776 return data | |
736 | 777 |
737 #========================================================================== | 778 #========================================================================== |
738 # SCM PROPERTIES | 779 # SCM PROPERTIES |
739 #========================================================================== | 780 #========================================================================== |
740 | 781 |