Allow uploading Network files to the server. No way to download yet.
This commit is contained in:
1 parent
a59a797a9f
commit
93cc8119eb
7 files changed
+124
-3
No files matched your search
+13
-1
@@ -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)
|
||||
@@ -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),
|
||||
|
||||
@@ -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 #
|
||||
|
||||
@@ -30,7 +30,10 @@ HTML_MINIFY = True
|
||||
SETTINGS_DIR = os.path.dirname(__file__)
|
||||
PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
|
||||
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
|
||||
TEMPLATE_PATH = os.path.join(PROJECT_PATH,'Templates')
|
||||
TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'Templates')
|
||||
|
||||
MEDIA_URL = '/Media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'Media')
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
@@ -68,6 +71,7 @@ TEMPLATES = [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'django.template.context_processors.media',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -42,7 +42,12 @@
|
||||
<li><a href="/index">Index</a></li>
|
||||
<li><a href="/greens">Greens</a></li>
|
||||
<li><a href="/search">Search</a></li>
|
||||
<li><a href="/newTest">New Test</a></li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li class="header">ACTIONS</li>
|
||||
<li><a href="/newTest">Create Test</a></li>
|
||||
<li><a href="/newNetwork">Upload Net</a></li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
@@ -50,6 +55,11 @@
|
||||
<li><a href="/users">Users</a></li>
|
||||
<li><a href="/events">Events</a></li>
|
||||
<li><a href="/machines">Machines</a></li>
|
||||
<li><a href="/networks">Networks</a></li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li class="header">SUPPORT</li>
|
||||
<li><a href="{{config.framework}}">OpenBench</a></li>
|
||||
<li><a href="https://discord.gg/HNXsgfS">Discord</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
{% extends "OpenBench/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<th>Engine</th>
|
||||
<th>Uploader</th>
|
||||
<th>Name</th>
|
||||
<th>Hash</th>
|
||||
<th>Downloads</th>
|
||||
</tr>
|
||||
|
||||
{% for network in networks %}
|
||||
<tr>
|
||||
<td>{{network.engine}}</td>
|
||||
<td><a href="/user/{{network.author}}">{{network.author}}</a></td>
|
||||
<td>{{network.name}}</td>
|
||||
<td>{{network.sha256}}</td>
|
||||
<td style="text-align: right">{{network.downloads}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,21 @@
|
||||
{% extends "OpenBench/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
<label>Name</label><input name="name"><br>
|
||||
<label>Weights</label><input name="netfile" type="file"><br>
|
||||
|
||||
<label>Engine</label> <select id="engine" name="engine">
|
||||
{% for engine in config.engines %}
|
||||
<option value="{{engine}}">{{engine}}</option>
|
||||
{% endfor %}
|
||||
<option selected value=""></option>
|
||||
</select><br>
|
||||
|
||||
<input type="submit" value="Upload">
|
||||
<form>
|
||||
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user