diff --git a/src/gameservers/views.py b/src/gameservers/views.py index d0c6bf5..09fa4b7 100644 --- a/src/gameservers/views.py +++ b/src/gameservers/views.py @@ -1,7 +1,8 @@ + from django.shortcuts import render from django.views import generic -from .models import Server, PopulationHistory +from .models import Server, PlayerHistory class ServerListView(generic.ListView): model = Server @@ -12,7 +13,13 @@ class ServerDetailView(generic.DetailView): def get_context_data(self, **kwargs): context = super(ServerDetailView, self).get_context_data(**kwargs) server = context['server'] - # HACK: 24 hours for the last 7 days, might want to change this - context['population'] = PopulationHistory.objects.filter(server=server)[:7*24*4] + + history = PlayerHistory() + points = history.get_points(server) + context['player_history'] = points + + timestamp, players = points[0] + context['last_updated'] = timestamp + context['online_players'] = players return context diff --git a/src/templates/gameservers/server_detail.html b/src/templates/gameservers/server_detail.html index ff519e0..b00f5b9 100644 --- a/src/templates/gameservers/server_detail.html +++ b/src/templates/gameservers/server_detail.html @@ -18,12 +18,10 @@ {% endif %}

Server History

- {% with population|first as status %} -

Last updated - {{status.timestamp|timesince}} - ago.

-

Online players: {{status.players}}

- {% endwith %} +

Last updated + {{last_updated|timesince}} + ago.

+

Online players: {{online_players}}

@@ -34,8 +32,9 @@