Add user view
This commit is contained in:
1 parent
e0159edd35
commit
8af4b023c4
7 files changed
+95
-50
No files matched your search
+15
-3
@@ -1,6 +1,8 @@
|
|||||||
from django.db.models import CharField, IntegerField, BooleanField
|
from django.db.models import CharField, IntegerField, BooleanField, FloatField
|
||||||
from django.db.models import FloatField, ForeignKey, DateTimeField
|
from django.db.models import ForeignKey, DateTimeField, OneToOneField
|
||||||
from django.db.models import PROTECT, Model
|
from django.db.models import CASCADE, PROTECT, Model
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
|
||||||
class LogEvent(Model):
|
class LogEvent(Model):
|
||||||
|
|
||||||
@@ -21,6 +23,16 @@ class Engine(Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{0} ({1})'.format(self.name, self.bench)
|
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):
|
class Machine(Model):
|
||||||
|
|
||||||
owner = CharField(max_length=64)
|
owner = CharField(max_length=64)
|
||||||
|
|||||||
+3
-1
@@ -7,9 +7,11 @@ urlpatterns = [
|
|||||||
path(r'login/', OpenBench.views.login),
|
path(r'login/', OpenBench.views.login),
|
||||||
path(r'logout/', OpenBench.views.logout),
|
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'index/<int:page>/', OpenBench.views.index),
|
path(r'index/<int:page>/', 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'newTest/', OpenBench.views.newTest),
|
||||||
path(r'editTest/<int:id>/', OpenBench.views.editTest),
|
path(r'editTest/<int:id>/', OpenBench.views.editTest),
|
||||||
|
|||||||
+36
-22
@@ -9,7 +9,8 @@ from django.contrib.auth.models import User
|
|||||||
|
|
||||||
from OpenBench.config import *
|
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
|
# Wrap django.shortcuts.render to add framework settings
|
||||||
def render(request, template, data):
|
def render(request, template, data):
|
||||||
@@ -33,40 +34,34 @@ def register(request):
|
|||||||
user.save()
|
user.save()
|
||||||
loginUser(request, user)
|
loginUser(request, user)
|
||||||
|
|
||||||
|
# Wrap the User in a Profile
|
||||||
|
profile = Profile()
|
||||||
|
profile.user = user
|
||||||
|
profile.save()
|
||||||
|
|
||||||
# Log the registration
|
# Log the registration
|
||||||
event = LogEvent()
|
event = LogEvent()
|
||||||
event.data = "Created user {0}".format(request.POST['username'])
|
event.data = 'Created user {0}'.format(request.POST['username'])
|
||||||
event.save()
|
event.save()
|
||||||
|
|
||||||
return HttpResponseRedirect("/index/")
|
return HttpResponseRedirect('/index/')
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
|
|
||||||
# User trying to view the login page
|
# User trying to view the login page
|
||||||
if request.method == "GET":
|
if request.method == 'GET':
|
||||||
return render(request, "login.html", {})
|
return render(request, 'login.html', {})
|
||||||
|
|
||||||
# Attempt to login the user, and return to index
|
# 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)
|
loginUser(request, user)
|
||||||
return HttpResponseRedirect("/index/")
|
return HttpResponseRedirect('/index/')
|
||||||
|
|
||||||
def logout(request):
|
def logout(request):
|
||||||
|
|
||||||
# Logout the user and return to index
|
# Logout the user and return to index
|
||||||
logoutUser(request)
|
logoutUser(request)
|
||||||
return HttpResponseRedirect("/index/")
|
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)
|
|
||||||
|
|
||||||
def index(request, page=0):
|
def index(request, page=0):
|
||||||
|
|
||||||
@@ -93,13 +88,32 @@ def index(request, page=0):
|
|||||||
# Save my @nitrocan @defenchess
|
# Save my @nitrocan @defenchess
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'pending' : [],
|
'pending' : pending,
|
||||||
'active' : [],
|
'active' : active,
|
||||||
'completed' : [],
|
'completed' : completed,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'index.html', data)
|
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):
|
def newTest(request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</title>
|
</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
@@ -25,19 +24,20 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li class="listheader"> CONTENT </li>
|
<li class="listheader"> CONTENT</li>
|
||||||
<li> <a href="/index"> Index </a> </li>
|
<li><a href="/index">Home</a></li>
|
||||||
<li> <a href="/newTest/"> New Test </a> </li>
|
<li><a href="/users">Users</a></li>
|
||||||
<li> <a href="/eventLog"> Event Log </a> </li>
|
<li><a href="/machines">Machines</a></li>
|
||||||
|
<li><a href="/eventLog">Event Log</a></li>
|
||||||
|
<li><a href="/newTest">Create Test</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li class="listheader"> LINKS </li>
|
<li class="listheader">LINKS</li>
|
||||||
<li> <a href="{{config.homepage}}">{{config.engine}}</a> </li>
|
<li><a href="{{config.homepage}}">{{config.engine}}</a></li>
|
||||||
<li> <a href="{{config.framework}}"> OpenBench </a> </li>
|
<li><a href="{{config.framework}}">OpenBench </a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -6,14 +6,11 @@
|
|||||||
Index
|
Index
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h2>Pending</h2>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="tabletitle">TEST</th>
|
|
||||||
<th class="tabletitle">DIFF</th>
|
|
||||||
<th class="tabletitle">APPROVE</th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
{% for test in pending %}
|
{% for test in pending %}
|
||||||
<tr class={{test.status}}>
|
<tr class={{test.status}}>
|
||||||
<td style="text-align:left;font-weight:bold">
|
<td style="text-align:left;font-weight:bold">
|
||||||
@@ -26,15 +23,9 @@ Index
|
|||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th class="tabletitle">AUTHOR</th>
|
|
||||||
<th class="tabletitle">TEST</th>
|
|
||||||
<th class="tabletitle">DIFF</th>
|
|
||||||
<th class="tabletitle">STATS</th>
|
|
||||||
<th class="tabletitle">ELO</th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
|
<h2>Approved</h2>
|
||||||
|
<table>
|
||||||
{% for test in active %}
|
{% for test in active %}
|
||||||
<tr class={{test.status}}>
|
<tr class={{test.status}}>
|
||||||
<td style="text-align:left;font-weight:bold">
|
<td style="text-align:left;font-weight:bold">
|
||||||
@@ -50,7 +41,6 @@ Index
|
|||||||
{{test.eloupper|twoDigitPrecision}}] <br> Games: {{test.games}}
|
{{test.eloupper|twoDigitPrecision}}] <br> Games: {{test.games}}
|
||||||
W: {{test.wins}} L: {{test.losses}} D: {{test.draws}}
|
W: {{test.wins}} L: {{test.losses}} D: {{test.draws}}
|
||||||
</strong></td>
|
</strong></td>
|
||||||
<td> {{enginetest.elo|twoDigitPrecision}} </td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
@@ -69,7 +59,6 @@ Index
|
|||||||
{{test.eloupper|twoDigitPrecision}}] <br> Games: {{test.games}}
|
{{test.eloupper|twoDigitPrecision}}] <br> Games: {{test.games}}
|
||||||
W: {{test.wins}} L: {{test.losses}} D: {{test.draws}}
|
W: {{test.wins}} L: {{test.losses}} D: {{test.draws}}
|
||||||
</strong></td>
|
</strong></td>
|
||||||
<td> {{enginetest.elo|twoDigitPrecision}} </td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
{% extends "OpenBench/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Event Log
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block style %}
|
||||||
|
{% load static %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Username</th>
|
||||||
|
<th>Games</th>
|
||||||
|
<th>Tests</th>
|
||||||
|
<th>Repository</th>
|
||||||
|
</tr>
|
||||||
|
{% for profile in profiles %}
|
||||||
|
<tr>
|
||||||
|
<td>{{profile.user.username}}</td>
|
||||||
|
<td>{{profile.games}}</td>
|
||||||
|
<td>{{profile.tests}}</td>
|
||||||
|
<td>{{profile.repo}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
<table>
|
||||||
|
{% endblock %}
|
||||||
BIN
Binary file not shown.
Reference in new issue
Block a user