def POST(self): http_input = web.input(tournament_id=None) tournament_id = http_input.tournament_id if tournament_id is None: raise web.notfound() tournament = Tournament.get(int(tournament_id), joined_attrs=["results"]) if tournament is None: raise web.notfound() results_grid = tournament_forms.EditResultsGrid().bind(tournament.results, data=http_input) if results_grid.validate(): # If the form was properly filled, updates the model and returns the standard table # Besides, we sort the results "from the outside" since they are directly returned (commit & no load) results_grid.sync() tournament.sort_results() results = config.views.results(tournament) statistics = config.views.statistics(tournament) else: # Otherwise, returns the editing grid results = config.views.results_admin(tournament, results_grid) statistics = None # Returns the dictionary return dict(results=results, statistics=statistics)
def POST(self): # Reads the HTTP request parameters tournament_id = web.input().tournament_id status = web.input().status # Updates the status tournament = Tournament.get(int(tournament_id), joined_attrs=["results"]) tournament.subscribe(config.session_manager.user, status) return dict( statistics=config.views.statistics(tournament), results=config.views.results(tournament) )
def GET(self): tournament_id = web.input(tournament_id=None).tournament_id if tournament_id is None: raise web.notfound() tournament = Tournament.get(int(tournament_id), joined_attrs=["results"]) if tournament is None: raise web.notfound() results_grid = tournament_forms.EditResultsGrid().bind(tournament.results) return config.views.results_admin(tournament, results_grid)
def POST(self): # Reads the HTTP request parameters tournament_id = web.input().tournament_id comment = web.input().comment # Appends the comment # TODO: variables are ambiguous tournament = Tournament.get(int(tournament_id), joined_attrs=["comments"]) added_comment = tournament.add_comment(config.session_manager.user, comment) # Registers an email notification http.register_hook(lambda: notify_via_email(added_comment, Events.NEW)) # Returns the dictionary return config.views.comment(added_comment)
def get_command(self): tournament_choosen = None if not self.all_tournaments: return NavigationCommand("mainpage", 'There is no tournament in the database') while not tournament_choosen: self.print_table( ["id", "name"], [(str(tournament.id), tournament.name) for tournament in self.all_tournaments], "List of all the tournament in the data base:", ) id = input("Tournament's id: ") if id.isdigit(): tournament_choosen = Tournament.get(int(id)) if tournament_choosen: return ContinueCommand(tournament_choosen) print("Enter the tournament's id")