Skip to content

Instantly share code, notes, and snippets.

@justanr
Created October 27, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justanr/f52662efbf661ba14c9d to your computer and use it in GitHub Desktop.
Save justanr/f52662efbf661ba14c9d to your computer and use it in GitHub Desktop.
class UserNotFound(Exception):
@classmethod
def by_username(cls, username):
return cls("No user found with username: {0}".format(username))
def find_user(username):
user = User.query.filter_by(username==username).first()
if not user:
raise UserNotFound.by_username(username)
return user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment