def remove_from_league(user_id): """ Remove a certain user_id from their league, only if the draft hasn't already started """ #Current user's id, used to identify their data account = Account.get_or_insert(user_id) if league_key(account.league).get() and league_key( account.league).get().draft_current_position == 0: #Remove user's choices and lineup for the league choice = choice_key(account_key(user_id), account.league).get() if choice: lineup_query = Lineup.query(ancestor=choice.key).fetch() for lineup in lineup_query: lineup.key.delete() choice.key.delete() #If this is the last person in the league, or this is the commissioner, delete it after they leave players = Account.query().filter( Account.league == account.league).fetch() if len(players) == 1 or account.league == account.key.id(): past_league = account.league #Remove User's association with league account.league = '0' account.put() delete_league(past_league) #Remove User's association with league account.league = '0' account.put()
def get_or_create_account(user): """Called periodically to get (all pages) to get the current user, or to create a new one if null""" account = Account.get_or_insert(user.user_id(), nickname=user.nickname(), league='0') if account.league == None: account.league = '0' account.put() return account
def add_to_league(user_id, league_id): account = Account.get_or_insert(user_id) #Add choice key for league choice = Choice.get_or_insert(str(league_id), parent=account.key) choice.put() #Add user to league account.league = league_id account.put()
def add_to_league(user_id, league_id): """ Add a certain user_id to a certain league_id """ account = Account.get_or_insert(user_id) #Add choice key for league choice = Choice.get_or_insert(str(league_id), parent=account.key) choice.put() #Add user to league account.league = league_id account.put()
def remove_from_league(user_id): #Current user's id, used to identify their data account = Account.get_or_insert(user_id) #Remove user's choices and lineup for the league choice = Choice_key(account_key(user_id), account.league).get() if choice: lineup_query = Lineup.query(ancestor=choice.key).fetch() for lineup in lineup_query: lineup.key.delete() choice.key.delete() #If this is the last person in the league, delete it after they leave players = Account.query().filter(Account.league == account.league).fetch() if len(players) == 1: past_league = account.league #Remove User's association with league account.league = '0' account.put() delete_league(past_league) #Remove User's association with league account.league = '0' account.put()
def get_or_create_account(user): account = Account.get_or_insert(user.user_id(), nickname=user.nickname(), league='0') if account.league == None: account.league = '0' account.put() return account