def post(self): super(AddTeam, self).post() manager = self.request.get('manager', "") year = ffdb.FFDBSeason.current_season() try: self.validate_name(manager, self.user) except ValueError as e: self.error(str(e)) else: # Create a new team object or update an existing one team = ff.FFTeam(year, self.user.user_id(), manager=manager, create=True) # Look up the team in the data store to make sure it is there # before redirecting back to the team page if team != None: temp_team = None while temp_team == None: league = ff.FFLeague(year) temp_team = league.get_team(manager=manager) self.redirect('/myteam.html')
def get(self): super(GetTeam, self).get() manager = self.request.get('manager', None) team = ff.FFTeam(year=self.year, manager=manager) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(team.get_properties()))
def get(self): super(EditTeam, self).get(2) no_user = self.user == None # Allow team creation in week 1 since auction sometimes happens in # this week. can_create = self.league.current_week() <= 1 team = None self.add_tab(Tab("Substitutions", "subs")) self.add_tab(Tab("Change Name", "changename")) if not no_user: # Try and load the team for this userid. There may not be one if # the user who is logged in has not entered one. try: team = ff.FFTeam(self.year, userid=self.user.user_id()) except KeyError as e: team = None else: if team != None: team.populate_fixtures() self.set_value('no_user', no_user) self.set_value('can_create', can_create) self.set_value('team', team) self.set_title("Edit Team") self.render("myteam.html")
def get(self): """ Get method called when data is submitted """ super(RemovePlayer, self).get() manager = self.request.get('manager', None) squad_num = int(self.request.get('squad_num', None)) # If undo is set then remove the player completely and refund the price # otherwise just move them to ex-players undo = int(self.request.get('undo', 0)) != 0 result = False error = "" team = ff.FFTeam(self.year, manager=manager) # First sanity check this request # User must be an administrator if not self.admin: error = "Error: User must be an administrator" elif manager == None or squad_num == None: error = "Error: Null value supplied" elif team == None: error = "Error: No team found for '{}'".format(manager) elif squad_num < 0 or squad_num > team.SQUADSIZE: error = "Error: Squad number {0} out of range".format(squad_num) else: # The parameters seem OK so remove the player from the team team.remove_player(squad_num, undo) result = True # Data to return in json format output = { 'result': result, # Result of this operation 'error': error } # error string if anything went wrong self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(output))
def get(self): """ Get method called when data is submitted """ super(AddPlayer, self).get() player_key = self.request.get('player', None) manager = self.request.get('manager', None) price = self.request.get('price', None) # max_squad_num may be set to a lower value during the auction max_squad_num = int(self.request.get('max', ff.FFTeam.SQUADSIZE)) result = False error = "" squad_num = -1 team = ff.FFTeam(self.year, manager=manager) player = ff.FFPlayerList(self.year, player_key=player_key).find_player(player_key) # First sanity check this request # User must be an administrator if not self.admin: error = "Error: User must be an administrator" elif player_key == None or manager == None or price == None: error = "Error: Null value supplied" elif not self.is_float(price): error = "Error: Price supplied is not a valid number" elif team == None: error = "Error: No team found for '{}'".format(manager) elif player == None: error = "Error: No player found for '{}'".format(player_key) elif player.manager != None: error = "Error: '{}' already belongs to '{}'".format( player.name, player.manager) else: # The parameters seem OK so try adding a player to the team try: squad_num = team.add_player(player, float(price), max_squad_num=max_squad_num) except ff.TeamError as e: error = "Error: {}".format(str(e)) else: result = True # Data to return in json format output = { 'result': result, # Result of this operation 'error': error, # error string if anything went wrong 'squad_num': squad_num } # squad number if call succeeded self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(output))
def get(self): super(GetValidSubs, self).get() manager = self.request.get('manager', None) squad_num = int(self.request.get('squad_num', -1)) team = ff.FFTeam(self.year, manager=manager) valid_values = [] for i in range(ff.FFTeam.SQUADSIZE): if team.can_sub(squad_num, i): valid_values.append(i) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({'valid_values': valid_values}))
def get(self): super(ViewTeams, self).get(1) manager = self.request.get('manager', None) self.set_value('manager', manager) self.set_value('team', ff.FFTeam(self.year, manager=manager)) submenu = OrderedDict() for team in self.league: # Make sure the manager name is url safe. i.e. no spaces etc. submenu[team.manager] = "./teams.html?manager={}".format( team.safemgr) self.set_value('submenu', submenu) self.set_title("Team Sheet") self.add_tab(Tab("Team Sheet", "teamsheet")) self.add_tab(Tab("Ex-players", "explayers")) self.render("teams.html")
def post(self): super(Sub, self).post() manager = self.request.get('manager', "") team = ff.FFTeam(self.year, manager=manager) sn1 = int(self.request.get('sn1', -1)) sn2 = int(self.request.get('sn2', -1)) if team == None: self.error("No team found for '{}'", manager) elif team.userid != self.user.user_id(): self.error("Only the owner of this team may update it") else: try: team.swap_players(sn1, sn2) except ff.TeamError as e: self.error("Error: {}".format(str(e))) else: #@@@ should loop until datastore update is visible but for now # just wait a moment sleep(0.5) self.redirect('/myteam.html')