Split get_user into _by_id, _by_username.
This commit is contained in:
parent
22d16693f3
commit
4bcfd9958a
1 changed files with 16 additions and 7 deletions
|
@ -1242,18 +1242,27 @@ class PDBUserMixin:
|
||||||
return user_id
|
return user_id
|
||||||
|
|
||||||
def get_user(self, username=None, id=None):
|
def get_user(self, username=None, id=None):
|
||||||
|
'''
|
||||||
|
Redirect to get_user_by_id or get_user_by_username.
|
||||||
|
'''
|
||||||
if not helpers.is_xor(id, username):
|
if not helpers.is_xor(id, username):
|
||||||
raise exceptions.NotExclusive(['id', 'username'])
|
raise exceptions.NotExclusive(['id', 'username'])
|
||||||
|
|
||||||
if username is not None:
|
if id:
|
||||||
user_row = self.sql_select_one('SELECT * FROM users WHERE username == ?', [username])
|
return self.get_user_by_id(id)
|
||||||
else:
|
else:
|
||||||
user_row = self.sql_select_one('SELECT * FROM users WHERE id == ?', [id])
|
return self.get_user_by_username(username)
|
||||||
|
|
||||||
if user_row is not None:
|
def get_user_by_id(self, id):
|
||||||
return self.get_cached_instance('user', user_row)
|
return self.get_thing_by_id('user', id)
|
||||||
else:
|
|
||||||
raise exceptions.NoSuchUser(username or id)
|
def get_user_by_username(self, username):
|
||||||
|
user_row = self.sql_select_one('SELECT * FROM users WHERE username == ?', [username])
|
||||||
|
|
||||||
|
if user_row is None:
|
||||||
|
raise exceptions.NoSuchUser(username)
|
||||||
|
|
||||||
|
return self.get_cached_instance('user', user_row)
|
||||||
|
|
||||||
def get_user_count(self):
|
def get_user_count(self):
|
||||||
return self.sql_select_one('SELECT COUNT(id) FROM users')[0]
|
return self.sql_select_one('SELECT COUNT(id) FROM users')[0]
|
||||||
|
|
Loading…
Reference in a new issue