diff options
author | Marian Sigler <m@qjym.de> | 2012-09-26 03:42:24 +0200 |
---|---|---|
committer | Marian Sigler <m@qjym.de> | 2012-09-26 03:42:24 +0200 |
commit | fc2b6762d5c8c2ac9c5003ddbaa53bdb13a64ed4 (patch) | |
tree | df9e7f53c2307740b6c97209b4419c23b7311fa9 /account.py | |
parent | 7216ec0a7fe4051611990c237652eaaa50e26e42 (diff) | |
download | web-fc2b6762d5c8c2ac9c5003ddbaa53bdb13a64ed4.tar.gz web-fc2b6762d5c8c2ac9c5003ddbaa53bdb13a64ed4.tar.bz2 web-fc2b6762d5c8c2ac9c5003ddbaa53bdb13a64ed4.zip |
account.py: Fix find(); Add get_by_uid()
Diffstat (limited to 'account.py')
-rw-r--r-- | account.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -52,6 +52,7 @@ class AccountService: >> all_accounts = service.find() # find all accounts >> print([x.uid for x in all_accounts]) >> service.find_by_uid('test') # find users by uid + >> service.get_by_uid('test') # same, raise NoSuchUserError if no match >> service.find_by_mail('test@test.de') # find users by mail >> service.find_by_uid('test*', wildcard=True) # find with wildcards @@ -91,6 +92,17 @@ class AccountService: return acc + def get_by_uid(self, uid): + """ + Find a single user by uid. Unlike find_by_uid, don't return a list but + raise ValueError if there is no such user. + """ + users = self.find_by_uid(uid) + if len(users) != 1: + raise NoSuchUserError('No such user') + + return users[0] + def find_by_uid(self, uid, wildcard=False): return self.find({'uid':uid}, wildcard) @@ -121,7 +133,7 @@ class AccountService: accounts = [] for a in data: - accounts.append(Account(a[1]['uid'],a[1]['mail'])) + accounts.append(Account(a[1]['uid'][0], a[1]['mail'][0])) self._unbind() @@ -282,3 +294,7 @@ class Account: new_mail = new_mail.encode('utf8') self.mail = new_mail + + +class NoSuchUserError(ValueError): + pass |