]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add links to the game modes in the stat line.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 10 Apr 2014 12:29:50 +0000 (08:29 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 10 Apr 2014 12:29:50 +0000 (08:29 -0400)
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.

xonstat/templates/main_index.mako
xonstat/views/main.py

index 4d9d5dd64603563c7b8480cc29e6d6eae68160fc..faa52383e323ccbc1d9376ce7858d6024a400738 100644 (file)
@@ -19,7 +19,7 @@ Leaderboard
     % endif
 
     % if day_stat_line is not None:
-    <p id="statline">${day_stat_line}</p>
+    <p id="statline">${day_stat_line|n}</p>
     % endif
   </div>
 </%block>
index e26de5216c79c8ce4adf90ab2b7c20ec17d4c602..21bd02698c4cf999c7fe64c101bb017e2114de75 100644 (file)
@@ -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],
+                "<a href='{}'>{}</a>".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