From: Ant Zucaro Date: Thu, 10 Apr 2014 12:29:50 +0000 (-0400) Subject: Add links to the game modes in the stat line. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=20b805e34fc9ce6110b5ab06f3ef85af9804c249;p=xonotic%2Fxonstat.git Add links to the game modes in the stat line. The implementation of this is a bit funky. See the comment in main.py for the get_day_summary_stats function call. Long story short is I picked what I believe to be the lesser of two evils - I'm assembling a complex string inside the view instead of putting a Python code block directly in the template. --- diff --git a/xonstat/templates/main_index.mako b/xonstat/templates/main_index.mako index 4d9d5dd..faa5238 100644 --- a/xonstat/templates/main_index.mako +++ b/xonstat/templates/main_index.mako @@ -19,7 +19,7 @@ Leaderboard % endif % if day_stat_line is not None: -

${day_stat_line}

+

${day_stat_line|n}

% endif diff --git a/xonstat/views/main.py b/xonstat/views/main.py index e26de52..21bd026 100644 --- a/xonstat/views/main.py +++ b/xonstat/views/main.py @@ -68,7 +68,7 @@ def get_summary_stats(): @cache_region('hourly_term') -def get_day_summary_stats(): +def get_day_summary_stats(request): """ Gets the following aggregate statistics about the past 24 hours: - the number of active players (day_active_players) @@ -108,9 +108,19 @@ def get_day_summary_stats(): if total_games == 0: day_stat_line = None else: + # This is ugly because we're doing template-like stuff within the + # view code. The alternative isn't any better, though: we would + # have to assemble the string inside the template by using a Python + # code block. For now I'll leave it like this since it is the lesser + # of two evils IMO. in_paren = ", ".join(["{} {}".format( - g[1], g[0]) for g in games[:5]] - ) + g[1], + "{}".format( + request.route_url("game_index", _query={'type':g[0]}), + g[0] + ) + ) for g in games[:5]]) + if len(games) > 5: in_paren += ", {} other".format(other_games) @@ -282,7 +292,7 @@ def _main_index_data(request): # summary statistics for the tagline try: summary_stats = get_summary_stats() - day_stat_line = get_day_summary_stats() + day_stat_line = get_day_summary_stats(request) except: summary_stats = None