Allow proper upload, download, deletion, and setting default of Networks
This commit is contained in:
1 parent
6d7008c35d
commit
48cfff38c7
8 files changed
+176
-79
No files matched your search
@@ -26,3 +26,4 @@ django.contrib.admin.site.register(OpenBench.models.Machine)
|
||||
django.contrib.admin.site.register(OpenBench.models.Result)
|
||||
django.contrib.admin.site.register(OpenBench.models.Test)
|
||||
django.contrib.admin.site.register(OpenBench.models.LogEvent)
|
||||
django.contrib.admin.site.register(OpenBench.models.Network)
|
||||
+2
-2
@@ -135,7 +135,7 @@ class LogEvent(Model):
|
||||
|
||||
class Network(Model):
|
||||
|
||||
downloads = IntegerField(default=0)
|
||||
default = BooleanField(default=False)
|
||||
sha256 = CharField(max_length=8)
|
||||
name = CharField(max_length=64)
|
||||
engine = CharField(max_length=64)
|
||||
@@ -143,4 +143,4 @@ class Network(Model):
|
||||
created = DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return '{}-{1} ({2})'.format(self.engine, self.name, self.sha256)
|
||||
return '[{}] {} ({})'.format(self.engine, self.name, self.sha256)
|
||||
@@ -229,7 +229,15 @@ a:link, a:visited, a:hover, a:active {
|
||||
|
||||
#content a:not(.TitleLink) {
|
||||
font-weight: 100;
|
||||
color: #8bbad6;
|
||||
color: #8BBAD6;
|
||||
}
|
||||
|
||||
#content a:is(.redlink) {
|
||||
color: #FF4D4D;
|
||||
}
|
||||
|
||||
#content a:is(.unstarred) {
|
||||
color: #808080;
|
||||
}
|
||||
|
||||
#content h1, h2, h3 {
|
||||
|
||||
+4
-3
@@ -42,7 +42,6 @@ urlpatterns = [
|
||||
django.urls.path(r'events/', OpenBench.views.events),
|
||||
django.urls.path(r'events/<int:page>/', OpenBench.views.events),
|
||||
django.urls.path(r'machines/', OpenBench.views.machines),
|
||||
django.urls.path(r'networks/', OpenBench.views.networks),
|
||||
|
||||
# Links for viewing and managing tests (maintain Legacy)
|
||||
django.urls.path(r'test/<int:id>/', OpenBench.views.test),
|
||||
@@ -50,8 +49,10 @@ urlpatterns = [
|
||||
django.urls.path(r'test/<int:id>/<str:action>', OpenBench.views.test),
|
||||
django.urls.path(r'newTest/', OpenBench.views.newTest),
|
||||
|
||||
django.urls.path(r'newNetwork/', OpenBench.views.newNetwork),
|
||||
django.urls.path(r'networks/<str:sha256>', OpenBench.views.downloadNetwork),
|
||||
# Links for viewing and managing Networks
|
||||
django.urls.path(r'networks/', OpenBench.views.networks),
|
||||
django.urls.path(r'networks/<str:action>/', OpenBench.views.networks),
|
||||
django.urls.path(r'networks/<str:action>/<str:sha256>', OpenBench.views.networks),
|
||||
|
||||
# Links for the Client to work with the Server
|
||||
django.urls.path(r'clientGetFiles/', OpenBench.views.clientGetFiles),
|
||||
|
||||
+73
-41
@@ -18,7 +18,7 @@
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
import os, hashlib, mimetypes
|
||||
import os, hashlib, mimetypes, datetime
|
||||
|
||||
import django.http
|
||||
import django.shortcuts
|
||||
@@ -331,17 +331,6 @@ def machines(request):
|
||||
data = {'machines' : OpenBench.utils.getRecentMachines()}
|
||||
return render(request, 'machines.html', data)
|
||||
|
||||
def networks(request):
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# GET : Return information about all of the Networks that have been #
|
||||
# uploaded to the Framework at any point in time #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
networks = Network.objects.all().order_by('-id')
|
||||
return render(request, 'networks.html', {'networks' : networks})
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# TEST MANAGEMENT VIEWS #
|
||||
@@ -426,7 +415,8 @@ def newTest(request):
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
if request.method == 'GET':
|
||||
return render(request, 'newTest.html')
|
||||
data = { 'networks' : Network.objects.all() }
|
||||
return render(request, 'newTest.html', data)
|
||||
|
||||
test, errors = OpenBench.utils.createNewTest(request)
|
||||
if errors != [] and errors != None:
|
||||
@@ -457,7 +447,43 @@ def newTest(request):
|
||||
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
def newNetwork(request):
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# NETWORK MANAGEMENT VIEWS #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
def networks(request, action=None, sha256=None):
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# GET : There are three possible GET lookups. [1] Fetch a view of all #
|
||||
# the Networks on the framework. [2] Fetch a template to upload a #
|
||||
# new Network to the framework. [3] Download the contents of a #
|
||||
# Network that is already saved on the framework. #
|
||||
# #
|
||||
# POST : There are four possible POST lookups. Download, Upload, Default #
|
||||
# and Delete. Downloads are open, but all others are gated by the #
|
||||
# credentials of the User. #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
if action == None:
|
||||
networks = Network.objects.all().order_by('-id')
|
||||
return render(request, 'networks.html', {'networks' : networks})
|
||||
|
||||
if action.upper() == 'DOWNLOAD':
|
||||
|
||||
if not Network.objects.filter(sha256=sha256):
|
||||
return index(request, error='No Network found with matching SHA256')
|
||||
|
||||
netfile = os.path.join(MEDIA_ROOT, sha256)
|
||||
fwrapper = FileWrapper(open(netfile, 'rb'), 8192)
|
||||
response = FileResponse(fwrapper, content_type='application/octet-stream')
|
||||
|
||||
response['Expires'] = (datetime.datetime.utcnow() + datetime.timedelta(days=7)).ctime()
|
||||
response['Content-Length'] = os.path.getsize(netfile)
|
||||
response['Content-Disposition'] = 'attachment; filename=' + sha256
|
||||
return response
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
return django.http.HttpResponseRedirect('/login/')
|
||||
@@ -465,44 +491,50 @@ def newNetwork(request):
|
||||
if not Profile.objects.get(user=request.user).approver:
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
if request.method == 'GET':
|
||||
return render(request, 'uploadnet.html', {})
|
||||
if action.upper() == 'UPLOAD':
|
||||
|
||||
engine = request.POST['engine']
|
||||
netfile = request.FILES['netfile']
|
||||
sha256 = hashlib.sha256(netfile.file.read()).hexdigest()[:8].upper()
|
||||
if request.method == 'GET':
|
||||
return render(request, 'uploadnet.html', {})
|
||||
|
||||
if Network.objects.filter(sha256=sha256):
|
||||
return index(request, error='Network with that hash already exists')
|
||||
engine = request.POST['engine']
|
||||
netfile = request.FILES['netfile']
|
||||
sha256 = hashlib.sha256(netfile.file.read()).hexdigest()[:8].upper()
|
||||
|
||||
if engine not in OpenBench.utils.OPENBENCH_CONFIG['engines'].keys():
|
||||
return index(request, error='No Engine found with matching name')
|
||||
if Network.objects.filter(sha256=sha256):
|
||||
return index(request, error='Network with that hash already exists')
|
||||
|
||||
fsystem = FileSystemStorage()
|
||||
fname = fsystem.save(sha256, netfile)
|
||||
if engine not in OpenBench.utils.OPENBENCH_CONFIG['engines'].keys():
|
||||
return index(request, error='No Engine found with matching name')
|
||||
|
||||
Network.objects.create(
|
||||
sha256=sha256, name=request.POST['name'],
|
||||
engine=engine, author=request.user.username);
|
||||
FileSystemStorage().save(sha256, netfile)
|
||||
|
||||
return index(request)
|
||||
Network.objects.create(
|
||||
sha256=sha256, name=request.POST['name'],
|
||||
engine=engine, author=request.user.username);
|
||||
|
||||
def downloadNetwork(request, sha256):
|
||||
return index(request)
|
||||
|
||||
if not Network.objects.filter(sha256=sha256):
|
||||
return index(request, error='No Network found with matching SHA256')
|
||||
if action.upper() == 'DEFAULT':
|
||||
|
||||
netfile = os.path.join(MEDIA_ROOT, sha256)
|
||||
fwrapper = FileWrapper(open(netfile, 'rb'), 8192)
|
||||
response = FileResponse(fwrapper, content_type='application/octet-stream')
|
||||
if not Network.objects.filter(sha256=sha256):
|
||||
return index(request, error='No Network found with matching SHA256')
|
||||
|
||||
network = Network.objects.get(sha256=sha256)
|
||||
network.downloads = network.downloads + 1
|
||||
network.save()
|
||||
network = Network.objects.get(sha256=sha256)
|
||||
Network.objects.filter(engine=network.engine).update(default=False)
|
||||
network.default = True; network.save()
|
||||
|
||||
return django.http.HttpResponseRedirect('/networks/')
|
||||
|
||||
if action.upper() == 'DELETE':
|
||||
|
||||
if not Network.objects.filter(sha256=sha256):
|
||||
return index(request, error='No Network found with matching SHA256')
|
||||
|
||||
Network.objects.get(sha256=sha256).delete()
|
||||
FileSystemStorage().delete(sha256)
|
||||
|
||||
return django.http.HttpResponseRedirect('/networks/')
|
||||
|
||||
response['Content-Length'] = os.path.getsize(netfile)
|
||||
response['Content-Disposition'] = 'attachment; filename=' + sha256
|
||||
return response
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# CLIENT HOOK VIEWS #
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
<head>
|
||||
<link rel="stylesheet" href="{% static 'style.css' %}">
|
||||
<link rel="icon" type="image/svg+xml" href="{% static 'logo.svg' %}">
|
||||
<link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css ' rel='stylesheet'>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,200;0,400;1,100&display=swap" rel="stylesheet">
|
||||
|
||||
<title>OpenBench</title>
|
||||
<script>
|
||||
{% block scripts %}
|
||||
@@ -32,7 +34,7 @@
|
||||
<li><a href="/logout/">Logout</a></li>
|
||||
<li><a href="/profile/">Profile</a></li>
|
||||
{% else %}
|
||||
<li><a href="/login">Login </a></li>
|
||||
<li><a href="/login">Login</a></li>
|
||||
<li><a href="/register">Register</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
@@ -47,7 +49,7 @@
|
||||
<ul>
|
||||
<li class="header">ACTIONS</li>
|
||||
<li><a href="/newTest">Create Test</a></li>
|
||||
<li><a href="/newNetwork">Upload Net</a></li>
|
||||
<li><a href="/networks/upload">Upload Net</a></li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
{% extends "OpenBench/base.html" %}
|
||||
|
||||
{% block style %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Engine</th>
|
||||
<th>Uploader</th>
|
||||
<th>Name</th>
|
||||
<th>Hash</th>
|
||||
<th>Downloads</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
{% for network in networks %}
|
||||
<tr>
|
||||
|
||||
{% if network.default %}
|
||||
<td><i class="fas fa-star" aria-hidden="true"></i></td>
|
||||
{% else %}
|
||||
<td><a class="unstarred" href="/networks/default/{{network.sha256}}">
|
||||
<i class="far fa-star" aria-hidden="true"></i></a></td>
|
||||
{% endif %}
|
||||
|
||||
<td>{{network.engine}}</td>
|
||||
<td><a href="/user/{{network.author}}">{{network.author}}</a></td>
|
||||
<td><a href="/networks/{{network.sha256}}">{{network.name}}</a></td>
|
||||
<td><a href="/networks/download/{{network.sha256}}">{{network.name}}</a></td>
|
||||
<td>{{network.sha256}}</td>
|
||||
<td style="text-align: right">{{network.downloads}}</td>
|
||||
|
||||
<td><a class="redlink" onclick="return confirm('YOU ARE DELETING THIS NETWORK FILE FOREVER')" href="/networks/delete/{{network.sha256}}">
|
||||
<i class="fas fa-minus-circle"></i></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
@@ -5,35 +5,74 @@
|
||||
// Take the settings from OpenBench/config.py for each engine
|
||||
// and generate a new dictionary in javascript that can be used
|
||||
|
||||
var configurations = {
|
||||
{% for name, data in config.engines.items %}
|
||||
'{{name}}' : {
|
||||
{% for type, settings in data.testmodes.items %}
|
||||
'{{type}}' : {
|
||||
"threads" : "{{settings.threads}}",
|
||||
"hash" : "{{settings.hash}}",
|
||||
"timecontrol" : "{{settings.timecontrol}}"
|
||||
},
|
||||
{% endfor %}
|
||||
var Configurations = {
|
||||
{% for name, data in config.engines.items %}
|
||||
'{{name}}' : {
|
||||
{% for type, settings in data.testmodes.items %}
|
||||
'{{type}}' : {
|
||||
"threads" : "{{settings.threads}}",
|
||||
"hash" : "{{settings.hash}}",
|
||||
"timecontrol" : "{{settings.timecontrol}}"
|
||||
},
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
},
|
||||
{% endfor %}
|
||||
};
|
||||
|
||||
var Networks = [
|
||||
{% for network in networks %}
|
||||
{
|
||||
"name" : "{{network.name}}",
|
||||
"engine" : "{{network.engine}}",
|
||||
"default" : "{{network.default}}",
|
||||
},
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
function configure(mode) {
|
||||
|
||||
// Find the selected engine
|
||||
var selection = document.getElementById("enginename");
|
||||
var engine = selection.options[selection.selectedIndex].value;
|
||||
var engine = selection.options[selection.selectedIndex].value;
|
||||
|
||||
// Parse out the needed configuration settings
|
||||
var threads = configurations[engine][mode]["threads"];
|
||||
var hash = configurations[engine][mode]["hash"];
|
||||
var timecontrol = configurations[engine][mode]["timecontrol"];
|
||||
if (mode != null) {
|
||||
|
||||
// Adjust all the fields to auto-fill the settings
|
||||
document.getElementById("devoptions").value = "Threads=" + threads + " Hash=" + hash;
|
||||
document.getElementById("baseoptions").value = "Threads=" + threads + " Hash=" + hash;
|
||||
document.getElementById("timecontrol").value = timecontrol;
|
||||
// Parse out the needed configuration settings
|
||||
var threads = Configurations[engine][mode]["threads"];
|
||||
var hash = Configurations[engine][mode]["hash"];
|
||||
var timecontrol = Configurations[engine][mode]["timecontrol"];
|
||||
|
||||
// Adjust all the fields to auto-fill the settings
|
||||
document.getElementById("devoptions").value = "Threads=" + threads + " Hash=" + hash;
|
||||
document.getElementById("baseoptions").value = "Threads=" + threads + " Hash=" + hash;
|
||||
document.getElementById("timecontrol").value = timecontrol;
|
||||
}
|
||||
|
||||
// Fetch each option selection for Dev & Base
|
||||
devnet = document.getElementById("devnetwork");
|
||||
basenet = document.getElementById("basenetwork");
|
||||
|
||||
// Remove all options initially
|
||||
while (devnet.length) devnet.remove(0);
|
||||
while (basenet.length) basenet.remove(0);
|
||||
|
||||
for (const network of Networks) {
|
||||
|
||||
if (network.engine !== engine)
|
||||
continue;
|
||||
|
||||
// Create a new option for both fields
|
||||
var devopt = document.createElement("option");
|
||||
var baseopt = document.createElement("option");
|
||||
|
||||
devopt.text = devopt.value = network.name;
|
||||
baseopt.text = baseopt.value = network.name;
|
||||
|
||||
devopt.selected = (network.default == "True");
|
||||
baseopt.selected = (network.default == "True");
|
||||
|
||||
devnet.add(devopt); basenet.add(baseopt);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () { configure('stc'); }, false);
|
||||
@@ -50,9 +89,9 @@
|
||||
<label> Name </label> <select id="enginename" name="enginename">
|
||||
{% for engine in config.engines %}
|
||||
{% if engine == profile.engine %}
|
||||
<option selected value="{{engine}}">{{engine}}</option>
|
||||
<option onClick="configure(null)" selected value="{{engine}}">{{engine}}</option>
|
||||
{% else %}
|
||||
<option value="{{engine}}">{{engine}}</option>
|
||||
<option onClick="configure(null)" value="{{engine}}">{{engine}}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<option value="{{engine}}">{{engine}}</option>
|
||||
@@ -63,13 +102,13 @@
|
||||
<label> Bench </label> <input name="devbench"><br>
|
||||
<label> Branch </label> <input name="devbranch" autofocus><br>
|
||||
<label> Options </label> <input id="devoptions" name="devoptions"><br>
|
||||
<label> Network </label> <input name="devnetwork"><br>
|
||||
<label> Network </label> <select id="devnetwork" name="devnetwork"></select><br>
|
||||
|
||||
<h3> Base Settings </h3>
|
||||
<label> Bench </label> <input name="basebench"><br>
|
||||
<label> Branch </label> <input value="master" name="basebranch"><br>
|
||||
<label> Options </label> <input id="baseoptions" name="baseoptions"><br>
|
||||
<label> Network </label> <input name="basenetwork"><br>
|
||||
<label> Network </label> <select id="basenetwork" name="basenetwork"></select><br>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -91,7 +130,7 @@
|
||||
<label> Lower </label> <input value="{{config.sprt.elolower}}" name="elolower"><br>
|
||||
<label> Upper </label> <input value="{{config.sprt.eloupper}}" name="eloupper"><br>
|
||||
<label> Alpha </label> <input value="{{config.sprt.alpha}}" name="alpha"><br>
|
||||
<label> Beta </label> <input value="{{config.sprt.beta}}" name="beta"><br>
|
||||
<label> Beta </label> <input value="{{config.sprt.beta}}" name="beta"><br>
|
||||
|
||||
<h3> Test Settings </h3>
|
||||
<label> Priority </label> <input value="0" name="priority"><br>
|
||||
@@ -104,9 +143,9 @@
|
||||
</form>
|
||||
|
||||
<div id="test-mode-buttons">
|
||||
<button class="left-floated" onClick="configure('stc')">Setup STC</button>
|
||||
<button class="left-floated" onClick="configure('stc')">Setup STC</button>
|
||||
<button class="right-floated" onClick="configure('ltc')">Setup LTC</button><br>
|
||||
<button class="left-floated" onClick="configure('smpstc')">Setup SMP STC</button>
|
||||
<button class="left-floated" onClick="configure('smpstc')">Setup SMP STC</button>
|
||||
<button class="right-floated" onClick="configure('smpltc')">Setup SMP LTC</button>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user