from google.appengine.api import users
from google.appengine.ext import db

from model import User

@db.transactional
def create_user(google_user):
    user = User(
        google_user=google_user
    )
    user.put()
    return user

def get_current_user():
    google_user = users.get_current_user()
    user = get_user_model_for(google_user)
    return user

def get_user_model_for(google_user=None):
    return User.all().filter('google_user =', google_user).get()

def get_user_model_by_id_or_nick(id_or_nick):
    if id_or_nick.isdigit():
        return User.get_by_id(int(id_or_nick))
    else:
        return User.all().filter('nickname_lower = ', id_or_nick.lower()).get()
from google.appengine.api import users
from google.appengine.ext import db

from model import User

latest_signup = None

@db.transactional
def create_user(google_user):
    global latest_signup
    user = User(
        google_user=google_user
    )
    user.put()
    latest_signup = user
    return user

def get_current_user():
    google_user = users.get_current_user()
    
    if latest_signup != None and google_user == latest_signup.google_user:
        return latest_signup
        
    user = get_user_model_for(google_user)
    return user

def get_user_model_for(google_user=None):
    return User.all().filter('google_user =', google_user).get()

def get_user_model_by_id_or_nick(id_or_nick):
    if id_or_nick.isdigit():
        return User.get_by_id(int(id_or_nick))
    else:
        return User.all().filter('nickname_lower = ', id_or_nick.lower()).get()
Fix bug where user could not be found
Fix bug where user could not be found

This problem only occured when a request tried to find the user right
after it had been created.
