From 8af4b023c4f122b0bf01d6d61b36924c5374fc7a Mon Sep 17 00:00:00 2001 From: AndyGrant Date: Sat, 9 Jun 2018 19:30:20 -0400 Subject: [PATCH] Add user view --- OpenBench/models.py | 18 ++++++++-- OpenBench/urls.py | 4 ++- OpenBench/views.py | 58 ++++++++++++++++++++------------- Templates/OpenBench/base.html | 18 +++++----- Templates/OpenBench/index.html | 19 +++-------- Templates/OpenBench/users.html | 28 ++++++++++++++++ db.sqlite3 | Bin 54272 -> 56320 bytes 7 files changed, 95 insertions(+), 50 deletions(-) create mode 100644 Templates/OpenBench/users.html diff --git a/OpenBench/models.py b/OpenBench/models.py index 9ad233f..4622f67 100644 --- a/OpenBench/models.py +++ b/OpenBench/models.py @@ -1,6 +1,8 @@ -from django.db.models import CharField, IntegerField, BooleanField -from django.db.models import FloatField, ForeignKey, DateTimeField -from django.db.models import PROTECT, Model +from django.db.models import CharField, IntegerField, BooleanField, FloatField +from django.db.models import ForeignKey, DateTimeField, OneToOneField +from django.db.models import CASCADE, PROTECT, Model +from django.contrib.auth.models import User + class LogEvent(Model): @@ -21,6 +23,16 @@ class Engine(Model): def __str__(self): return '{0} ({1})'.format(self.name, self.bench) +class Profile(Model): + + user = OneToOneField(User, on_delete=CASCADE) + games = IntegerField(default=0) + tests = IntegerField(default=0) + repo = CharField(max_length=256) + + def __str__(self): + return self.user.__str__() + class Machine(Model): owner = CharField(max_length=64) diff --git a/OpenBench/urls.py b/OpenBench/urls.py index f2d6687..e8f664f 100644 --- a/OpenBench/urls.py +++ b/OpenBench/urls.py @@ -7,9 +7,11 @@ urlpatterns = [ path(r'login/', OpenBench.views.login), path(r'logout/', OpenBench.views.logout), - path(r'eventLog/', OpenBench.views.eventLog), path(r'index/', OpenBench.views.index), path(r'index//', OpenBench.views.index), + path(r'users/', OpenBench.views.users), + path(r'machines/', OpenBench.views.machines), + path(r'eventLog/', OpenBench.views.eventLog), path(r'newTest/', OpenBench.views.newTest), path(r'editTest//', OpenBench.views.editTest), diff --git a/OpenBench/views.py b/OpenBench/views.py index 6f3cde2..0f12a10 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -9,7 +9,8 @@ from django.contrib.auth.models import User from OpenBench.config import * -from OpenBench.models import LogEvent, Machine, Test +from OpenBench.models import LogEvent, Engine, Profile +from OpenBench.models import Machine, Results, Test # Wrap django.shortcuts.render to add framework settings def render(request, template, data): @@ -33,40 +34,34 @@ def register(request): user.save() loginUser(request, user) + # Wrap the User in a Profile + profile = Profile() + profile.user = user + profile.save() + # Log the registration event = LogEvent() - event.data = "Created user {0}".format(request.POST['username']) + event.data = 'Created user {0}'.format(request.POST['username']) event.save() - return HttpResponseRedirect("/index/") + return HttpResponseRedirect('/index/') def login(request): # User trying to view the login page - if request.method == "GET": - return render(request, "login.html", {}) + if request.method == 'GET': + return render(request, 'login.html', {}) # Attempt to login the user, and return to index - user = authenticate(username=request.POST["username"], password=request.POST["password"]) + user = authenticate(username=request.POST['username'], password=request.POST['password']) loginUser(request, user) - return HttpResponseRedirect("/index/") + return HttpResponseRedirect('/index/') def logout(request): # Logout the user and return to index logoutUser(request) - return HttpResponseRedirect("/index/") - -def eventLog(request): - - # Build context dictionary for template - data = {"events": []} - for event in LogEvent.objects.all(): - data["events"].append({ - "data" : event.data, - "creation" : event.creation}) - - return render(request, "eventLog.html", data) + return HttpResponseRedirect('/index/') def index(request, page=0): @@ -93,13 +88,32 @@ def index(request, page=0): # Save my @nitrocan @defenchess data = { - 'pending' : [], - 'active' : [], - 'completed' : [], + 'pending' : pending, + 'active' : active, + 'completed' : completed, } return render(request, 'index.html', data) +def users(request): + profiles = Profile.objects.all() + data = {'profiles' : Profile.objects.all()} + return render(request, 'users.html', data) + +def machines(request): + pass + +def eventLog(request): + + # Build context dictionary for template + data = {'events': []} + for event in LogEvent.objects.all(): + data['events'].append({ + 'data' : event.data, + 'creation' : event.creation}) + + return render(request, 'eventLog.html', data) + def newTest(request): pass diff --git a/Templates/OpenBench/base.html b/Templates/OpenBench/base.html index b5170da..da7d857 100644 --- a/Templates/OpenBench/base.html +++ b/Templates/OpenBench/base.html @@ -11,7 +11,6 @@ {% endblock %} - -
{% block content %} {% endblock %} diff --git a/Templates/OpenBench/index.html b/Templates/OpenBench/index.html index 199d85d..fe77d73 100644 --- a/Templates/OpenBench/index.html +++ b/Templates/OpenBench/index.html @@ -6,14 +6,11 @@ Index {% endblock %} + {% block content %} +

Pending

- - - - - {% for test in pending %} {% endfor %}
TESTDIFFAPPROVE
@@ -26,15 +23,9 @@ Index
- - - - - - - - +

Approved

+
AUTHORTESTDIFFSTATSELO
{% for test in active %} - {% endfor %} @@ -69,7 +59,6 @@ Index {{test.eloupper|twoDigitPrecision}}]
Games: {{test.games}} W: {{test.wins}} L: {{test.losses}} D: {{test.draws}} - {% endfor %}
@@ -50,7 +41,6 @@ Index {{test.eloupper|twoDigitPrecision}}]
Games: {{test.games}} W: {{test.wins}} L: {{test.losses}} D: {{test.draws}}
{{enginetest.elo|twoDigitPrecision}}
{{enginetest.elo|twoDigitPrecision}}
diff --git a/Templates/OpenBench/users.html b/Templates/OpenBench/users.html new file mode 100644 index 0000000..3405c02 --- /dev/null +++ b/Templates/OpenBench/users.html @@ -0,0 +1,28 @@ +{% extends "OpenBench/base.html" %} + +{% block title %} +Event Log +{% endblock %} + +{% block style %} +{% load static %} +{% endblock %} + +{% block content %} + + + + + + + + {% for profile in profiles %} + + + + + + + {% endfor %} +
UsernameGamesTestsRepository
{{profile.user.username}}{{profile.games}}{{profile.tests}}{{profile.repo}}
+{% endblock %} diff --git a/db.sqlite3 b/db.sqlite3 index b59a7d03bacf6e675ebb4ca865230d357c374d51..9c2bdf71ca5473fc3af5b9e07ca147990b33e58f 100644 GIT binary patch delta 2221 zcmd6o?N3`(9LMjuzti460Rvjf3SA$80j0DBS_<2cF$EU0&16iY&aT20NT5_Gi7!ZC za{;1p%1%OzzCg@;S~4T+hBLx6OVp?tiw}v@n7uM4E>7S0N{x8#xu*|+e}E+1ob$Qg z?>XOd?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