Use file url for SCAT
This commit is contained in:
parent
9ce925fd6a
commit
ff91a1e5fa
2 changed files with 29 additions and 35 deletions
|
@ -2,6 +2,8 @@ import os
|
||||||
import secrets
|
import secrets
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
import pyotp
|
import pyotp
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -148,16 +150,23 @@ class ProblemSubmitForm(ModelForm):
|
||||||
)
|
)
|
||||||
self.fields["judge"].choices = judge_choices
|
self.fields["judge"].choices = judge_choices
|
||||||
|
|
||||||
|
def allow_url_as_source(self):
|
||||||
|
key = self.cleaned_data["language"].key
|
||||||
|
filename = self.files["source_file"].name
|
||||||
|
if key == "OUTPUT" and self.problem.data_files.output_only:
|
||||||
|
return filename.endswith(".zip")
|
||||||
|
if key == "SCAT":
|
||||||
|
return filename.endswith(".sb3")
|
||||||
|
return False
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if "source_file" in self.files:
|
if "source_file" in self.files:
|
||||||
if (
|
if self.allow_url_as_source():
|
||||||
self.cleaned_data["language"].key in ["OUTPUT", "SCAT"]
|
|
||||||
and self.problem.data_files.output_only
|
|
||||||
):
|
|
||||||
filename = self.files["source_file"].name
|
filename = self.files["source_file"].name
|
||||||
if filename.endswith(".zip") or filename.endswith(".sb3"):
|
now = datetime.datetime.now()
|
||||||
|
timestamp = str(int(time.mktime(now.timetuple())))
|
||||||
self.source_file_name = (
|
self.source_file_name = (
|
||||||
secrets.token_hex(16) + "." + filename.split(".")[-1]
|
timestamp + secrets.token_hex(5) + "." + filename.split(".")[-1]
|
||||||
)
|
)
|
||||||
filepath = os.path.join(
|
filepath = os.path.join(
|
||||||
settings.DMOJ_SUBMISSION_ROOT, self.source_file_name
|
settings.DMOJ_SUBMISSION_ROOT, self.source_file_name
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
{% block js_media %}
|
{% block js_media %}
|
||||||
<script type="text/javascript" src="{{ ACE_URL }}/ace.js"></script>
|
<script type="text/javascript" src="{{ ACE_URL }}/ace.js"></script>
|
||||||
<script type="text/javascript" src="{{ static('jszip/jszip.min.js') }}"></script>
|
|
||||||
{{ form.media.js }}
|
{{ form.media.js }}
|
||||||
{% compress js %}
|
{% compress js %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -139,29 +138,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_source_scratch(file) {
|
|
||||||
JSZip.loadAsync(file).then(function($content) {
|
|
||||||
return $content.files["project.json"].async('text');
|
|
||||||
}).then(function (src) {
|
|
||||||
update_submit_area(src);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#id_source_file').on('click change', function(e) {
|
$('#id_source_file').on('click change', function(e) {
|
||||||
var file = $(this)[0].files[0];
|
var file = $(this)[0].files[0];
|
||||||
if (file) {
|
if (file) {
|
||||||
if (file.name.endsWith('zip')) {
|
if (file.name.endsWith('zip')) {
|
||||||
update_submit_area(file.name);
|
update_submit_area(file.name);
|
||||||
}
|
}
|
||||||
{% if output_only %}
|
|
||||||
else if (file.name.endsWith('sb3')) {
|
else if (file.name.endsWith('sb3')) {
|
||||||
update_submit_area(file.name);
|
update_submit_area(file.name);
|
||||||
}
|
}
|
||||||
{% else %}
|
|
||||||
else if (file.name.endsWith('sb3')) {
|
|
||||||
get_source_scratch(file);
|
|
||||||
}
|
|
||||||
{% endif %}
|
|
||||||
else {
|
else {
|
||||||
get_source_default(file);
|
get_source_default(file);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue