endret litt på retrieve-user, tok i bruk nye hjelpefunksjoner

This commit is contained in:
Øyvind Almelid 2010-05-08 10:29:03 +00:00
parent 9b222debf2
commit b9f5c39a76
1 changed files with 9 additions and 9 deletions

View File

@ -30,24 +30,24 @@ def guess_data_type(string):
def retrieve_user(string, session): def retrieve_user(string, session):
first = session.query(User).filter(or_(User.name==string, User.card==string)).first() # first = session.query(User).filter(or_(User.name==string, User.card==string)).first()
if first: search = search_user(string,session)
print "Found user "+first.name if isinstance(search,User):
return first print "Found user "+search.name
return search
else: else:
list = session.query(User).filter(or_(User.name.like('%'+string+'%'),User.card.like('%'+string+'%'))).all() if len(search) == 0:
if len(list) == 0:
print "No users found matching your search" print "No users found matching your search"
return None return None
if len(list) == 1: if len(search) == 1:
print "Found one user: "+list[0].name print "Found one user: "+list[0].name
if confirm(): if confirm():
return list[0] return list[0]
else: else:
return None return None
else: else:
print "Found "+str(len(list))+" users:" print "Found "+str(len(search))+" users:"
return select_from_list(list) return select_from_list(search)
def confirm(prompt='Confirm? (y/n) '): def confirm(prompt='Confirm? (y/n) '):