From c792b9fd3bbc60bc5d7154d29409b217c349157b Mon Sep 17 00:00:00 2001 From: AndyGrant Date: Wed, 13 Jun 2018 22:01:03 -0400 Subject: [PATCH] Add update for profile last seen --- .gitignore | 3 ++- OpenBench/models.py | 1 + OpenBench/utils.py | 21 ++++++++++++++++----- OpenBench/views.py | 2 +- Templates/OpenBench/users.html | 2 ++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 2c43e1e..7a1d0d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc Client/* !Client/OpenBench.py -!Client/cleanup.sh \ No newline at end of file +!Client/cleanup.sh +OpenBench/migrations/* \ No newline at end of file diff --git a/OpenBench/models.py b/OpenBench/models.py index 601f628..ce8aca1 100644 --- a/OpenBench/models.py +++ b/OpenBench/models.py @@ -32,6 +32,7 @@ class Profile(Model): repo = CharField(max_length=256, blank=True) enabled = BooleanField(default=False) approver = BooleanField(default=False) + updated = DateTimeField(auto_now=True) def __str__(self): return self.user.__str__() diff --git a/OpenBench/utils.py b/OpenBench/utils.py index b634e62..2ef4eec 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -1,5 +1,6 @@ import math, requests, random +from django.utils import timezone from django.db.models import F from django.contrib.auth import authenticate @@ -224,11 +225,19 @@ def update(request, user): failed = sprt < test.lowerllr finished = passed or failed - # Update total # of games played for the User - Profile.objects.filter(user=user).update(games=F('games') + games) + # Updating times manually since .update() won't invoke + updated = timezone.now() - # Just force an update to Machine.update - Machine.objects.filter(id=machineid).update() + # Update total # of games played for the User + Profile.objects.filter(user=user).update( + games=F('games') + games, + updated=updated + ) + + # Update last time we saw a result + Machine.objects.filter(id=machineid).update( + updated=updated + ) # Update for the new results Result.objects.filter(id=resultid).update( @@ -238,6 +247,7 @@ def update(request, user): draws=F('draws') + draws, crashes=F('crashes') + crashes, timeloss=F('timeloss') + timeloss, + updated=updated ) # Finally, update test data and flags @@ -250,7 +260,8 @@ def update(request, user): elo=elo, passed=passed, failed=failed, - finished=finished + finished=finished, + updated=updated ) # Signal to stop completed tests diff --git a/OpenBench/views.py b/OpenBench/views.py index 9fc0fdc..b1e385c 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -149,7 +149,7 @@ def index(request, page=0, username=None, error=''): def users(request): # Build context dictionary for template - data = {'profiles' : Profile.objects.all()} + data = {'profiles' : Profile.objects.order_by('games')} return render(request, 'users.html', data) def viewUser(request, username): diff --git a/Templates/OpenBench/users.html b/Templates/OpenBench/users.html index 511aa97..c4c1a89 100644 --- a/Templates/OpenBench/users.html +++ b/Templates/OpenBench/users.html @@ -8,6 +8,7 @@ + @@ -17,6 +18,7 @@ {% for profile in profiles %} +
UsernameLast Seen Games Tests Repo
{{profile.user.username}}{{profile.updated|date:'Y-m-d H:i'}} {{profile.games}} {{profile.tests}} {{profile.repo}}