Allow uploading Network files to the server. No way to download yet.

This commit is contained in:
Andrew Grant committed 2020-12-20 19:03:57 -05:00
1 parent a59a797a9f
commit 93cc8119eb
7 files changed
+124 -3

No files matched your search

+13 -1
View File
@@ -19,7 +19,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
from django.db.models import CharField, IntegerField, BooleanField, FloatField
from django.db.models import ForeignKey, DateTimeField, OneToOneField
from django.db.models import ForeignKey, DateTimeField, OneToOneField, FileField
from django.db.models import CASCADE, PROTECT, Model
from django.contrib.auth.models import User
@@ -132,3 +132,15 @@ class LogEvent(Model):
def __str__(self):
return "{0} {1} {2}".format(self.author, str(self.test), self.data)
class Network(Model):
downloads = IntegerField(default=0)
sha256 = CharField(max_length=8)
name = CharField(max_length=64)
engine = CharField(max_length=64)
author = CharField(max_length=64)
created = DateTimeField(auto_now_add=True)
def __str__(self):
return '{}-{1} ({2})'.format(self.engine, self.name, self.sha256)
+2
View File
@@ -42,12 +42,14 @@ 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),
django.urls.path(r'viewTest/<int:id>/', 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'newNetwork/', OpenBench.views.newNetwork),
# Links for the Client to work with the Server
django.urls.path(r'clientGetFiles/', OpenBench.views.clientGetFiles),
+45
View File
@@ -18,6 +18,8 @@
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import os, hashlib
import django.http
import django.shortcuts
import django.contrib.auth
@@ -26,11 +28,14 @@ import OpenBench.config
import OpenBench.utils
from OpenBench.models import *
from OpenSite.settings import MEDIA_ROOT
from django.contrib.auth.models import User
from django.db.models import F
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.core.files.storage import FileSystemStorage
from htmlmin.decorators import not_minified_response
def render(request, template, content={}):
@@ -326,6 +331,17 @@ 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 #
@@ -441,6 +457,35 @@ def newTest(request):
return django.http.HttpResponseRedirect('/index/')
def newNetwork(request):
if not request.user.is_authenticated:
return django.http.HttpResponseRedirect('/login/')
if not Profile.objects.get(user=request.user).approver:
return django.http.HttpResponseRedirect('/index/')
if request.method == 'GET':
return render(request, 'uploadnet.html', {})
engine = request.POST['engine']
netfile = request.FILES['netfile']
sha256 = hashlib.sha256(netfile.file.read()).hexdigest()[:8].upper()
if Network.objects.filter(sha256=sha256):
return index(request, error='Network with that hash already exists')
if engine not in OpenBench.utils.OPENBENCH_CONFIG['engines'].keys():
return index(request, error='No Engine found with matching name')
fsystem = FileSystemStorage()
fname = fsystem.save(sha256, netfile)
Network.objects.create(
sha256=sha256, name=request.POST['name'],
engine=engine, author=request.user.username);
return index(request)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# CLIENT HOOK VIEWS #