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 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)
|
||||
|
||||
+3
-1
@@ -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/<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'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.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
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
{% endblock %}
|
||||
</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="sidebar">
|
||||
{% block sidebar %}
|
||||
@@ -25,19 +24,20 @@
|
||||
{% endif %}
|
||||
</ul>
|
||||
<ul>
|
||||
<li class="listheader"> CONTENT </li>
|
||||
<li> <a href="/index"> Index </a> </li>
|
||||
<li> <a href="/newTest/"> New Test </a> </li>
|
||||
<li> <a href="/eventLog"> Event Log </a> </li>
|
||||
<li class="listheader"> CONTENT</li>
|
||||
<li><a href="/index">Home</a></li>
|
||||
<li><a href="/users">Users</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>
|
||||
<li class="listheader"> LINKS </li>
|
||||
<li> <a href="{{config.homepage}}">{{config.engine}}</a> </li>
|
||||
<li> <a href="{{config.framework}}"> OpenBench </a> </li>
|
||||
<li class="listheader">LINKS</li>
|
||||
<li><a href="{{config.homepage}}">{{config.engine}}</a></li>
|
||||
<li><a href="{{config.framework}}">OpenBench </a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,14 +6,11 @@
|
||||
Index
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h2>Pending</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th class="tabletitle">TEST</th>
|
||||
<th class="tabletitle">DIFF</th>
|
||||
<th class="tabletitle">APPROVE</th>
|
||||
</tr>
|
||||
|
||||
{% for test in pending %}
|
||||
<tr class={{test.status}}>
|
||||
<td style="text-align:left;font-weight:bold">
|
||||
@@ -26,15 +23,9 @@ Index
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</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 %}
|
||||
<tr class={{test.status}}>
|
||||
<td style="text-align:left;font-weight:bold">
|
||||
@@ -50,7 +41,6 @@ Index
|
||||
{{test.eloupper|twoDigitPrecision}}] <br> Games: {{test.games}}
|
||||
W: {{test.wins}} L: {{test.losses}} D: {{test.draws}}
|
||||
</strong></td>
|
||||
<td> {{enginetest.elo|twoDigitPrecision}} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -69,7 +59,6 @@ Index
|
||||
{{test.eloupper|twoDigitPrecision}}] <br> Games: {{test.games}}
|
||||
W: {{test.wins}} L: {{test.losses}} D: {{test.draws}}
|
||||
</strong></td>
|
||||
<td> {{enginetest.elo|twoDigitPrecision}} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</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