Small cleanups
This commit is contained in:
1 parent
5ae64025aa
commit
b5b95ec9cf
5 files changed
+64
-53
No files matched your search
+1
-1
@@ -38,7 +38,7 @@ class Profile(Model):
|
|||||||
user = ForeignKey(User, PROTECT, related_name='user')
|
user = ForeignKey(User, PROTECT, related_name='user')
|
||||||
games = IntegerField(default=0)
|
games = IntegerField(default=0)
|
||||||
tests = IntegerField(default=0)
|
tests = IntegerField(default=0)
|
||||||
repos = JSONField()
|
repos = JSONField(default=dict)
|
||||||
engine = CharField(max_length=128, blank=True)
|
engine = CharField(max_length=128, blank=True)
|
||||||
enabled = BooleanField(default=False)
|
enabled = BooleanField(default=False)
|
||||||
approver = BooleanField(default=False)
|
approver = BooleanField(default=False)
|
||||||
|
|||||||
@@ -210,6 +210,9 @@ def compilerBlock(machine):
|
|||||||
string += '%-16s %-8s (%s)\n' % (engine, info[0], info[1])
|
string += '%-16s %-8s (%s)\n' % (engine, info[0], info[1])
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def removePrefix(value, prefix):
|
||||||
|
return value.removeprefix(prefix)
|
||||||
|
|
||||||
register = django.template.Library()
|
register = django.template.Library()
|
||||||
register.filter('oneDigitPrecision', oneDigitPrecision)
|
register.filter('oneDigitPrecision', oneDigitPrecision)
|
||||||
register.filter('twoDigitPrecision', twoDigitPrecision)
|
register.filter('twoDigitPrecision', twoDigitPrecision)
|
||||||
@@ -227,3 +230,4 @@ register.filter('testIdToPrettyName', testIdToPrettyName)
|
|||||||
register.filter('testIdToTimeControl', testIdToTimeControl)
|
register.filter('testIdToTimeControl', testIdToTimeControl)
|
||||||
register.filter('cpuflagsBlock', cpuflagsBlock)
|
register.filter('cpuflagsBlock', cpuflagsBlock)
|
||||||
register.filter('compilerBlock', compilerBlock)
|
register.filter('compilerBlock', compilerBlock)
|
||||||
|
register.filter('removePrefix', removePrefix)
|
||||||
+2
-2
@@ -22,12 +22,12 @@ import django.urls, OpenBench.views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
||||||
# Links for account managment
|
# Links for account management
|
||||||
django.urls.path(r'register/', OpenBench.views.register),
|
django.urls.path(r'register/', OpenBench.views.register),
|
||||||
django.urls.path(r'login/', OpenBench.views.login),
|
django.urls.path(r'login/', OpenBench.views.login),
|
||||||
django.urls.path(r'logout/', OpenBench.views.logout),
|
django.urls.path(r'logout/', OpenBench.views.logout),
|
||||||
django.urls.path(r'profile/', OpenBench.views.profile),
|
django.urls.path(r'profile/', OpenBench.views.profile),
|
||||||
django.urls.path(r'profileConfig/', OpenBench.views.profileConfig),
|
django.urls.path(r'profileConfig/', OpenBench.views.profile_config),
|
||||||
|
|
||||||
# Links for viewing test tables
|
# Links for viewing test tables
|
||||||
django.urls.path(r'index/', OpenBench.views.index),
|
django.urls.path(r'index/', OpenBench.views.index),
|
||||||
|
|||||||
+10
-10
@@ -200,32 +200,32 @@ def profile(request):
|
|||||||
|
|
||||||
return django.http.HttpResponseRedirect('/index/')
|
return django.http.HttpResponseRedirect('/index/')
|
||||||
|
|
||||||
def profileConfig(request):
|
def profile_config(request):
|
||||||
|
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return django.http.HttpResponseRedirect('/login/')
|
return django.http.HttpResponseRedirect('/login/')
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render(request, 'profile.html')
|
return render(request, 'profile.html')
|
||||||
|
|
||||||
profile = Profile.objects.filter(user=request.user)
|
profile = Profile.objects.get(user=request.user)
|
||||||
profile = profile.first()
|
|
||||||
|
|
||||||
changes = False # To check if any changes are made.
|
changes = False # To check if any changes are made.
|
||||||
|
|
||||||
default_status = request.POST.get('default-status', '')
|
default_status = request.POST.get('default-status', '')
|
||||||
|
|
||||||
if default_status != '':
|
if default_status != '':
|
||||||
# update the default engine
|
# update the default engine
|
||||||
profile.engine = default_status
|
profile.engine = default_status
|
||||||
changes = True
|
changes = True
|
||||||
|
|
||||||
deleted_repos = request.POST.get('deleted-repos', '[]')
|
deleted_repos = request.POST.get('deleted-repos', '[]')
|
||||||
deleted_repos_array = json.loads(deleted_repos)
|
deleted_repos_array = json.loads(deleted_repos)
|
||||||
|
|
||||||
for engine in deleted_repos_array:
|
for engine in deleted_repos_array:
|
||||||
if engine in profile.repos:
|
if engine in profile.repos:
|
||||||
del profile.repos[engine]
|
del profile.repos[engine]
|
||||||
|
|
||||||
if len(deleted_repos_array) != 0:
|
if len(deleted_repos_array) != 0:
|
||||||
changes = True
|
changes = True
|
||||||
|
|
||||||
@@ -237,15 +237,15 @@ def profileConfig(request):
|
|||||||
elif request.POST['new-engine-name'] != "None" and request.POST['new-engine-repo'].startswith('https://github.com/'):
|
elif request.POST['new-engine-name'] != "None" and request.POST['new-engine-repo'].startswith('https://github.com/'):
|
||||||
engine_name = request.POST['new-engine-name']
|
engine_name = request.POST['new-engine-name']
|
||||||
engine_repo = request.POST['new-engine-repo']
|
engine_repo = request.POST['new-engine-repo']
|
||||||
|
|
||||||
# Append the new engine and repo to the profile's repos field
|
# Append the new engine and repo to the profile's repos field
|
||||||
profile.repos[engine_name] = engine_repo
|
profile.repos[engine_name] = engine_repo
|
||||||
changes = True
|
changes = True
|
||||||
|
|
||||||
if changes:
|
if changes:
|
||||||
profile.save() # Save if any changes are made
|
profile.save() # Save if any changes are made
|
||||||
|
|
||||||
return django.http.HttpResponseRedirect('/index/')
|
return render(request, 'profile.html')
|
||||||
|
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
# TEST LIST VIEWS #
|
# TEST LIST VIEWS #
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
{% extends "OpenBench/base.html" %}
|
{% extends "OpenBench/base.html" %}
|
||||||
|
|
||||||
|
{% load static %}
|
||||||
|
{% load mytags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<form method="POST" action="/profile/">
|
<form method="POST" action="/profile/">
|
||||||
@@ -12,7 +15,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<label>Email</label><input value="{{ profile.user.email }}" name="email">
|
<label>Email</label><input value="{{ profile.user.email }}" name="email">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>New Password</label><input type="password" name="password1">
|
<label>New Password</label><input type="password" name="password1">
|
||||||
</div>
|
</div>
|
||||||
@@ -23,57 +26,61 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<hr>
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<form method="POST" action="/profileConfig/">
|
<form method="POST" action="/profileConfig/">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="col" id="engines-container">
|
<div class="form">
|
||||||
{% for engine, repo in profile.repos.items %}
|
<div class="col" id="engines-container">
|
||||||
<div class="row" id="engine-row-{{ engine }}">
|
|
||||||
<label>{{ engine }}</label>
|
|
||||||
<input type="text" name="engine-repo-{{ engine }}" value="{{ repo }}">
|
|
||||||
<input id="radio-{{engine}}" type="radio" name="default-status" value="{{ engine }}" {% if profile.engine == engine %}checked{% endif %}>
|
|
||||||
<span onclick="deleteRow(event)">
|
|
||||||
<i class="fa-solid fa-trash-can" style="color: #ff0000;" data-engine="{{ engine }}"></i>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<select name="new-engine-name">
|
|
||||||
<option value="None">None</option>
|
|
||||||
<option selected disabled hidden>Choose an engine</option>
|
|
||||||
{% for engine in config.engines.keys %}
|
|
||||||
{% if engine not in profile.repos %}
|
|
||||||
<option value="{{ engine }}">{{ engine }}</option>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
<input name="new-engine-repo">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<input type="hidden" name="deleted-repos" id="deleted-repos" value="[]">
|
<!-- Display engines which have repos already defined -->
|
||||||
<input class="anchorbutton btn-blue w-100" type="submit" name="add-engine" value="Update Engine">
|
{% for engine, repo in profile.repos.items %}
|
||||||
|
<div class="row" id="engine-row-{{ engine }}">
|
||||||
|
<label>{{ engine }}</label>
|
||||||
|
<input type="text" name="engine-repo-{{ engine }}" value="{{ repo|removePrefix:'https://github.com/' }}">
|
||||||
|
<input id="radio-{{engine}}" type="radio" name="default-status" value="{{ engine }}" {% if profile.engine == engine %}checked{% endif %}>
|
||||||
|
<span onclick="deleteRow(event)">
|
||||||
|
<i class="fa-solid fa-trash-can" style="color: #ff0000;" data-engine="{{ engine }}" ></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<label> <!-- CSS Hack -->
|
||||||
|
<select name="new-engine-name">
|
||||||
|
<option value="None">None</option>
|
||||||
|
<option selected disabled hidden>New Engine</option>
|
||||||
|
{% for engine in config.engines.keys %}
|
||||||
|
{% if engine not in profile.repos %}
|
||||||
|
<option value="{{ engine }}">{{ engine }}</option>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<input name="new-engine-repo">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="deleted-repos" id="deleted-repos" value="[]">
|
||||||
|
<input class="anchorbutton btn-blue w-100" type="submit" name="add-engine" value="Save Configuration">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function deleteRow(event) {
|
function deleteRow(event) {
|
||||||
|
|
||||||
const button = event.currentTarget.querySelector('i');
|
const button = event.currentTarget.querySelector('i');
|
||||||
const engine = button.getAttribute('data-engine');
|
const engine = button.getAttribute('data-engine');
|
||||||
const radioId = 'radio-' + engine;
|
const radio = document.getElementById('radio-' + engine);
|
||||||
const radio = document.getElementById(radioId);
|
|
||||||
|
if (engine && radio && radio.checked)
|
||||||
if (engine && radio && radio.checked) {
|
|
||||||
// Don't delete default engine.
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (engine) {
|
if (engine) {
|
||||||
// Perform the delete action here
|
// Perform the delete action here
|
||||||
console.log(`Deleting engine: ${engine}`);
|
console.log(`Deleting engine: ${engine}`);
|
||||||
|
|
||||||
// Remove the corresponding row from the DOM
|
// Remove the corresponding row from the DOM
|
||||||
const row = button.parentNode.parentNode;
|
const row = button.parentNode.parentNode;
|
||||||
row.parentNode.removeChild(row);
|
row.parentNode.removeChild(row);
|
||||||
@@ -81,13 +88,13 @@
|
|||||||
// Update the deleted-repos hidden input field with the deleted engine
|
// Update the deleted-repos hidden input field with the deleted engine
|
||||||
const deletedReposInput = document.getElementById('deleted-repos');
|
const deletedReposInput = document.getElementById('deleted-repos');
|
||||||
let deletedRepos = JSON.parse(deletedReposInput.value);
|
let deletedRepos = JSON.parse(deletedReposInput.value);
|
||||||
|
|
||||||
deletedRepos.push(engine);
|
deletedRepos.push(engine);
|
||||||
deletedReposInput.value = JSON.stringify(deletedRepos);
|
deletedReposInput.value = JSON.stringify(deletedRepos);
|
||||||
console.log(deletedRepos);
|
console.log(deletedRepos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in new issue
Block a user