Allow proper upload, download, deletion, and setting default of Networks

This commit is contained in:
Andrew Grant committed 2020-12-27 18:18:29 -05:00
1 parent 6d7008c35d
commit 48cfff38c7
8 files changed
+142 -45

No files matched your search

+1
View File
@@ -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.Result)
django.contrib.admin.site.register(OpenBench.models.Test) django.contrib.admin.site.register(OpenBench.models.Test)
django.contrib.admin.site.register(OpenBench.models.LogEvent) django.contrib.admin.site.register(OpenBench.models.LogEvent)
django.contrib.admin.site.register(OpenBench.models.Network)
+2 -2
View File
@@ -135,7 +135,7 @@ class LogEvent(Model):
class Network(Model): class Network(Model):
downloads = IntegerField(default=0) default = BooleanField(default=False)
sha256 = CharField(max_length=8) sha256 = CharField(max_length=8)
name = CharField(max_length=64) name = CharField(max_length=64)
engine = CharField(max_length=64) engine = CharField(max_length=64)
@@ -143,4 +143,4 @@ class Network(Model):
created = DateTimeField(auto_now_add=True) created = DateTimeField(auto_now_add=True)
def __str__(self): def __str__(self):
return '{}-{1} ({2})'.format(self.engine, self.name, self.sha256) return '[{}] {} ({})'.format(self.engine, self.name, self.sha256)
+9 -1
View File
@@ -229,7 +229,15 @@ a:link, a:visited, a:hover, a:active {
#content a:not(.TitleLink) { #content a:not(.TitleLink) {
font-weight: 100; font-weight: 100;
color: #8bbad6; color: #8BBAD6;
}
#content a:is(.redlink) {
color: #FF4D4D;
}
#content a:is(.unstarred) {
color: #808080;
} }
#content h1, h2, h3 { #content h1, h2, h3 {
+4 -3
View File
@@ -42,7 +42,6 @@ urlpatterns = [
django.urls.path(r'events/', OpenBench.views.events), django.urls.path(r'events/', OpenBench.views.events),
django.urls.path(r'events/<int:page>/', 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'machines/', OpenBench.views.machines),
django.urls.path(r'networks/', OpenBench.views.networks),
# Links for viewing and managing tests (maintain Legacy) # Links for viewing and managing tests (maintain Legacy)
django.urls.path(r'test/<int:id>/', OpenBench.views.test), 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'test/<int:id>/<str:action>', OpenBench.views.test),
django.urls.path(r'newTest/', OpenBench.views.newTest), django.urls.path(r'newTest/', OpenBench.views.newTest),
django.urls.path(r'newNetwork/', OpenBench.views.newNetwork), # Links for viewing and managing Networks
django.urls.path(r'networks/<str:sha256>', OpenBench.views.downloadNetwork), 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 # Links for the Client to work with the Server
django.urls.path(r'clientGetFiles/', OpenBench.views.clientGetFiles), django.urls.path(r'clientGetFiles/', OpenBench.views.clientGetFiles),
+58 -26
View File
@@ -18,7 +18,7 @@
# # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import os, hashlib, mimetypes import os, hashlib, mimetypes, datetime
import django.http import django.http
import django.shortcuts import django.shortcuts
@@ -331,17 +331,6 @@ def machines(request):
data = {'machines' : OpenBench.utils.getRecentMachines()} data = {'machines' : OpenBench.utils.getRecentMachines()}
return render(request, 'machines.html', data) 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 # # TEST MANAGEMENT VIEWS #
@@ -426,7 +415,8 @@ def newTest(request):
return django.http.HttpResponseRedirect('/index/') return django.http.HttpResponseRedirect('/index/')
if request.method == 'GET': 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) test, errors = OpenBench.utils.createNewTest(request)
if errors != [] and errors != None: if errors != [] and errors != None:
@@ -457,7 +447,43 @@ def newTest(request):
return django.http.HttpResponseRedirect('/index/') 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: if not request.user.is_authenticated:
return django.http.HttpResponseRedirect('/login/') return django.http.HttpResponseRedirect('/login/')
@@ -465,6 +491,8 @@ def newNetwork(request):
if not Profile.objects.get(user=request.user).approver: if not Profile.objects.get(user=request.user).approver:
return django.http.HttpResponseRedirect('/index/') return django.http.HttpResponseRedirect('/index/')
if action.upper() == 'UPLOAD':
if request.method == 'GET': if request.method == 'GET':
return render(request, 'uploadnet.html', {}) return render(request, 'uploadnet.html', {})
@@ -478,8 +506,7 @@ def newNetwork(request):
if engine not in OpenBench.utils.OPENBENCH_CONFIG['engines'].keys(): if engine not in OpenBench.utils.OPENBENCH_CONFIG['engines'].keys():
return index(request, error='No Engine found with matching name') return index(request, error='No Engine found with matching name')
fsystem = FileSystemStorage() FileSystemStorage().save(sha256, netfile)
fname = fsystem.save(sha256, netfile)
Network.objects.create( Network.objects.create(
sha256=sha256, name=request.POST['name'], sha256=sha256, name=request.POST['name'],
@@ -487,22 +514,27 @@ def newNetwork(request):
return index(request) return index(request)
def downloadNetwork(request, sha256): if action.upper() == 'DEFAULT':
if not Network.objects.filter(sha256=sha256): if not Network.objects.filter(sha256=sha256):
return index(request, error='No Network found with matching 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')
network = Network.objects.get(sha256=sha256) network = Network.objects.get(sha256=sha256)
network.downloads = network.downloads + 1 Network.objects.filter(engine=network.engine).update(default=False)
network.save() 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 # # CLIENT HOOK VIEWS #
+4 -2
View File
@@ -7,7 +7,9 @@
<head> <head>
<link rel="stylesheet" href="{% static 'style.css' %}"> <link rel="stylesheet" href="{% static 'style.css' %}">
<link rel="icon" type="image/svg+xml" href="{% static 'logo.svg' %}"> <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&amp;display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,200;0,400;1,100&amp;display=swap" rel="stylesheet">
<title>OpenBench</title> <title>OpenBench</title>
<script> <script>
{% block scripts %} {% block scripts %}
@@ -32,7 +34,7 @@
<li><a href="/logout/">Logout</a></li> <li><a href="/logout/">Logout</a></li>
<li><a href="/profile/">Profile</a></li> <li><a href="/profile/">Profile</a></li>
{% else %} {% else %}
<li><a href="/login">Login </a></li> <li><a href="/login">Login</a></li>
<li><a href="/register">Register</a></li> <li><a href="/register">Register</a></li>
{% endif %} {% endif %}
</ul> </ul>
@@ -47,7 +49,7 @@
<ul> <ul>
<li class="header">ACTIONS</li> <li class="header">ACTIONS</li>
<li><a href="/newTest">Create Test</a></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>
<ul> <ul>
+17 -3
View File
@@ -1,24 +1,38 @@
{% extends "OpenBench/base.html" %} {% extends "OpenBench/base.html" %}
{% block style %}
{% endblock %}
{% block content %} {% block content %}
<table> <table>
<tr> <tr>
<th></th>
<th>Engine</th> <th>Engine</th>
<th>Uploader</th> <th>Uploader</th>
<th>Name</th> <th>Name</th>
<th>Hash</th> <th>Hash</th>
<th>Downloads</th> <th></th>
</tr> </tr>
{% for network in networks %} {% for network in networks %}
<tr> <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>{{network.engine}}</td>
<td><a href="/user/{{network.author}}">{{network.author}}</a></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>{{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> </tr>
{% endfor %} {% endfor %}
+47 -8
View File
@@ -5,7 +5,7 @@
// Take the settings from OpenBench/config.py for each engine // Take the settings from OpenBench/config.py for each engine
// and generate a new dictionary in javascript that can be used // and generate a new dictionary in javascript that can be used
var configurations = { var Configurations = {
{% for name, data in config.engines.items %} {% for name, data in config.engines.items %}
'{{name}}' : { '{{name}}' : {
{% for type, settings in data.testmodes.items %} {% for type, settings in data.testmodes.items %}
@@ -19,16 +19,28 @@
{% endfor %} {% endfor %}
}; };
var Networks = [
{% for network in networks %}
{
"name" : "{{network.name}}",
"engine" : "{{network.engine}}",
"default" : "{{network.default}}",
},
{% endfor %}
];
function configure(mode) { function configure(mode) {
// Find the selected engine // Find the selected engine
var selection = document.getElementById("enginename"); var selection = document.getElementById("enginename");
var engine = selection.options[selection.selectedIndex].value; var engine = selection.options[selection.selectedIndex].value;
if (mode != null) {
// Parse out the needed configuration settings // Parse out the needed configuration settings
var threads = configurations[engine][mode]["threads"]; var threads = Configurations[engine][mode]["threads"];
var hash = configurations[engine][mode]["hash"]; var hash = Configurations[engine][mode]["hash"];
var timecontrol = configurations[engine][mode]["timecontrol"]; var timecontrol = Configurations[engine][mode]["timecontrol"];
// Adjust all the fields to auto-fill the settings // Adjust all the fields to auto-fill the settings
document.getElementById("devoptions").value = "Threads=" + threads + " Hash=" + hash; document.getElementById("devoptions").value = "Threads=" + threads + " Hash=" + hash;
@@ -36,6 +48,33 @@
document.getElementById("timecontrol").value = timecontrol; 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); document.addEventListener('DOMContentLoaded', function () { configure('stc'); }, false);
{% endblock %} {% endblock %}
@@ -50,9 +89,9 @@
<label> Name </label> <select id="enginename" name="enginename"> <label> Name </label> <select id="enginename" name="enginename">
{% for engine in config.engines %} {% for engine in config.engines %}
{% if engine == profile.engine %} {% if engine == profile.engine %}
<option selected value="{{engine}}">{{engine}}</option> <option onClick="configure(null)" selected value="{{engine}}">{{engine}}</option>
{% else %} {% else %}
<option value="{{engine}}">{{engine}}</option> <option onClick="configure(null)" value="{{engine}}">{{engine}}</option>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<option value="{{engine}}">{{engine}}</option> <option value="{{engine}}">{{engine}}</option>
@@ -63,13 +102,13 @@
<label> Bench </label> <input name="devbench"><br> <label> Bench </label> <input name="devbench"><br>
<label> Branch </label> <input name="devbranch" autofocus><br> <label> Branch </label> <input name="devbranch" autofocus><br>
<label> Options </label> <input id="devoptions" name="devoptions"><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> <h3> Base Settings </h3>
<label> Bench </label> <input name="basebench"><br> <label> Bench </label> <input name="basebench"><br>
<label> Branch </label> <input value="master" name="basebranch"><br> <label> Branch </label> <input value="master" name="basebranch"><br>
<label> Options </label> <input id="baseoptions" name="baseoptions"><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> </div>