Add more of the test view. Approve, Stop, Restart, and Delete tests

This commit is contained in:
AndyGrant committed 2018-06-10 21:30:45 -04:00
1 parent 96371ad961
commit b79d930875
6 files changed
+232 -15

No files matched your search

+18 -2
View File
@@ -48,8 +48,6 @@ td {
text-align: right;
}
.red:nth-child(even){background-color: #FAA5A5}
.red:nth-child(odd){background-color: #FA8E8E}
.green:nth-child(even){background-color: #2FFA62}
.green:nth-child(odd){background-color: #9DF779}
@@ -57,6 +55,9 @@ td {
.yellow:nth-child(even){background-color: #E9FA32}
.yellow:nth-child(odd){background-color: #EEF788}
.red:nth-child(even){background-color: #FAA5A5}
.red:nth-child(odd){background-color: #FA8E8E}
ul {
list-style-type: none;
display: block;
@@ -119,6 +120,7 @@ input[type=submit] {
border-radius: 4px;
cursor: pointer;
width: 100%;
font-weight: bold;
}
input[type=submit]:hover {
@@ -131,3 +133,17 @@ label, option {
font-weight:bold;
vertical-align: middle;
}
.buttonlink {
background-color: #4CAF50;
color: white;
padding: 8px 6px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
text-align: center;
display: inline-block;
width: 20%;
}
+1 -1
View File
@@ -55,7 +55,7 @@ def statParagraph(test):
eloupper = twoDigitPrecision(test.eloupper)
return 'SPRT @ {0}s Threads={1} Hash={2}MB<br>'.format(test.timecontrol, threads, hash) \
+ 'LLR: {0} ({1}, {2}) [{3}, {4}]<br>'.format(lowerllr, currentllr, upperllr, elolower, eloupper) \
+ 'LLR: {0} ({1}, {2}) [{3}, {4}]<br>'.format(currentllr, lowerllr, upperllr, elolower, eloupper) \
+ 'Games: {0} W: {1} L: {2} D: {3}'.format(test.games, test.wins, test.losses, test.draws)
def testResultColour(test):
+4 -1
View File
@@ -17,9 +17,12 @@ urlpatterns = [
path(r'eventLog/', OpenBench.views.eventLog),
path(r'newTest/', OpenBench.views.newTest),
path(r'editTest/<int:id>/', OpenBench.views.editTest),
path(r'viewTest/<int:id>/', OpenBench.views.viewTest),
path(r'editTest/<int:id>/', OpenBench.views.editTest),
path(r'approveTest/<int:id>/', OpenBench.views.approveTest),
path(r'restartTest/<int:id>/', OpenBench.views.restartTest),
path(r'stopTest/<int:id>/', OpenBench.views.stopTest),
path(r'deleteTest/<int:id>/', OpenBench.views.deleteTest),
path(r'getFiles/', OpenBench.views.getFiles),
path(r'getWorkload/', OpenBench.views.getFiles),
+101 -11
View File
@@ -91,15 +91,14 @@ def index(request, page=0, username=None, error=''):
# Get tests currently running
active = Test.objects.filter(approved=True)
active = active.exclude(passed=True)
active = active.exclude(failed=True)
active = active.exclude(finished=True)
active = active.exclude(deleted=True)
active = active.order_by('priority', 'currentllr')
# Get the last 50 completed tests
# Get the complted tests (sliced later)
completed = Test.objects.filter(finished=True)
completed = completed.exclude(deleted=True)
completed = completed.order_by('completion')
completed = completed.order_by('-completion')
if username != None: # View from just one user
pending = pending.filter(author=username)
@@ -110,7 +109,7 @@ def index(request, page=0, username=None, error=''):
data = {
'pending' : pending,
'active' : active,
'completed' : completed,
'completed' : completed[:50],
'error' : error,
}
@@ -132,7 +131,7 @@ def eventLog(request):
data = {'events': LogEvent.objects.all().order_by('-id')[:50]}
return render(request, 'eventLog.html', data)
@login_required
@login_required(login_url='/login/')
def newTest(request):
# User trying to view the new test page
@@ -160,10 +159,6 @@ def newTest(request):
except Exception as error:
return index(request, error=str(error))
@staff_member_required
def editTest(request, id):
pass
def viewTest(request, id):
try:
@@ -177,7 +172,11 @@ def viewTest(request, id):
except Exception as error:
return index(request, error=str(error))
@login_required
@login_required(login_url='/login/')
def editTest(request, id):
pass
@login_required(login_url='/login/')
def approveTest(request, id):
try:
@@ -190,12 +189,103 @@ def approveTest(request, id):
test = Test.objects.get(id=id)
test.approved = True
test.save()
# Log the test approval
event = LogEvent()
event.data = 'Approved test {0} ({1})'.format(str(test), test.id)
event.author = request.user.username
event.save()
return HttpResponseRedirect('/index/')
# Bad test id, permissions, or other
except Exception as error:
return index(request, error=str(error))
@login_required(login_url='/login/')
def restartTest(request, id):
try:
# Only let approvers or the author restart a test
test = Test.objects.get(id=id)
profile = Profile.objects.get(user=request.user)
if not profile.approver and test.author != profile.user.username:
raise Exception("Only Admins Or Test Owners Can Restart A Test")
# Restart the provided test
test = Test.objects.get(id=id)
if test.passed or test.failed:
raise Exception("Test Already Finished via SPRT")
test.finished = False
test.save()
# Log the test stopping
event = LogEvent()
event.data = 'Restart test {0} ({1})'.format(str(test), test.id)
event.author = request.user.username
event.save()
return HttpResponseRedirect('/index/')
# Bad test id, permissions, or other
except Exception as error:
return index(request, error=str(error))
@login_required(login_url='/login/')
def stopTest(request, id):
try:
# Only let approvers or the author stop a test
test = Test.objects.get(id=id)
profile = Profile.objects.get(user=request.user)
if not profile.approver and test.author != profile.user.username:
raise Exception("Only Admins Or Test Owners Can Stop A Test")
# Stop the provided test
test = Test.objects.get(id=id)
test.finished = True
test.save()
# Log the test stopping
event = LogEvent()
event.data = 'Stopped test {0} ({1})'.format(str(test), test.id)
event.author = request.user.username
event.save()
return HttpResponseRedirect('/index/')
# Bad test id, permissions, or other
except Exception as error:
return index(request, error=str(error))
@login_required(login_url='/login/')
def deleteTest(request, id):
try:
# Only let approvers or the author delete a test
test = Test.objects.get(id=id)
profile = Profile.objects.get(user=request.user)
if not profile.approver and test.author != profile.user.username:
raise Exception("Only Admins Or Test Owners Can Delete A Test")
# Delete the provided test
test = Test.objects.get(id=id)
test.delete = True
test.save()
# Log the test deltion
event = LogEvent()
event.data = 'Deleted test {0} ({1})'.format(str(test), test.id)
event.author = request.user.username
event.save()
return HttpResponseRedirect('/index/')
# Bad test id, permissions, or other
except Exception as error:
return index(request, error=str(error))
def getFiles(request):
pass
+108
View File
@@ -0,0 +1,108 @@
{% extends "OpenBench/base.html" %}
{% load mytags %}
{% block style %}
{% load static %}
{% endblock %}
{% block content %}
<div style="float:left">
<table>
<tr>
<th style="text-align:left">Dev Branch</th>
<td style="text-align:left">{{test.dev.name}}</td>
</tr>
<tr>
<th style="text-align:left">Dev Bench</th>
<td style="text-align:left">{{test.dev.bench}}</td>
</tr>
<tr>
<th style="text-align:left">Dev Options</th>
<td style="text-align:left">{{test.devoptions}}</td>
</tr>
<tr>
<th style="text-align:left">Dev Protocol</th>
<td style="text-align:left">{{test.dev.protocol}}</td>
</tr>
<tr>
<th style="text-align:left">Dev Sha</th>
<td style="text-align:left">{{test.dev.sha}}</td>
</tr>
<tr>
<th style="text-align:left">Base Branch</th>
<td style="text-align:left">{{test.base.name}}</td>
</tr>
<tr>
<th style="text-align:left">Base Bench</th>
<td style="text-align:left">{{test.base.bench}}</td>
</tr>
<tr>
<th style="text-align:left">Base Options</th>
<td style="text-align:left">{{test.baseoptions}}</td>
</tr>
<tr>
<th style="text-align:left">Base Protocol</th>
<td style="text-align:left">{{test.base.protocol}}</td>
</tr>
<tr>
<th style="text-align:left">Base Sha</th>
<td style="text-align:left">{{test.base.sha}}</td>
</tr>
<tr>
<th style="text-align:left">Source Repo</th>
<td style="text-align:left">{{test.source}}</td>
</tr>
<tr>
<th style="text-align:left">Opening Book</th>
<td style="text-align:left">{{test.bookname}}</td>
</tr>
<tr>
<th style="text-align:left">Time Control</th>
<td style="text-align:left">{{test.timecontrol}}s</td>
</tr>
<tr>
<th style="text-align:left">Elo Bounds</th>
<td style="text-align:left">[{{test.elolower}}, {{test.eloupper}}]</td>
</tr>
<tr>
<th style="text-align:left">SPRT Bounds</th>
<td style="text-align:left">({{test.lowerllr|twoDigitPrecision}}, {{test.upperllr|twoDigitPrecision}})</td>
</tr>
<tr>
<th style="text-align:left">Creation</th>
<td style="text-align:left">{{test.creation|date:'Y-m-d H:i:s'}}</td>
</tr>
<tr>
<th style="text-align:left">Author</th>
<td style="text-align:left">{{test.author}}</td>
</tr>
</table>
</div>
<div style="float:left;margin-left:40px">
<h2>Actions</h2>
<a class="buttonlink" href="/approveTest/{{test.id}}/" style="background-color: #9DF779">Approve</a>
{% if test.finished %}
<a class="buttonlink" href="/restartTest/{{test.id}}/" style="background-color: #EEF788">Restart</a>
{% else %}
<a class="buttonlink" href="/stopTest/{{test.id}}/" style="background-color: #EEF788">Stop</a>
{% endif %}
<a class="buttonlink" href="/deleteTest/{{test.id}}/" style="background-color: #FA8E8E">Delete</a>
<h4>{{test.dev.name}} vs {{test.base.name}} <a href="{{test|gitDiffLink}}">DIFF</a></h4>
{% autoescape off %}
<pre>{{test|statParagraph}}</pre>
{% endautoescape %}
<form method="POST" action="/editTest/{{test.id}}/">
{% csrf_token %}
<label type="text">Priority</label>
<input style="width: 240px" type="text" value="{{test.priority}}" name="priority"></br>
<label type="text">Throughput</label>
<input style="width: 240px" type="text" value="{{test.throughput}}" name="throughput"></br>
<input type="submit" name="submit" value="Modify">
</form>
</div>
{% endblock %}
BIN
View File
Binary file not shown.