Skip to content

Commit

Permalink
Allow getting a user by id and nickname.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Jun 20, 2013
1 parent 0f53c91 commit be32cb9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions tahrir_api/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,32 @@ def get_person_email(self, person_id):
id=person_id).one().email
return None

def get_person(self, person_email):
def get_person(self, person_email=None, id=None, nickname=None):
"""
Convience function to retrieve a person object from an email
Convenience function to retrieve a person object from an email,
id, or nickname.
:type person_email: str
:param person_email: The email address of a Person in the database
:type id: str
:param id: The id of a Person in the database
:type nickname: str
:param nickname: The nickname of a Person in the database
"""

session = scoped_session(self.session_maker)
if self.person_exists(email=person_email):
return session.query(Person).filter_by(email=person_email).one()
return None
query = session.query(Person)

if person_email and self.person_exists(email=person_email):
return query.filter_by(email=person_email).one()
elif id and self.person_exists(id=id):
return query.filter_by(id=id).one()
elif nickname and self.person_exists(nickname=nickname):
return query.filter_by(nickname=nickname).one()
else:
return None

def delete_person(self, person_email):
"""
Expand Down

0 comments on commit be32cb9

Please sign in to comment.