Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file submission to problem page #1933

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions judge/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ def get_context_data(self, **kwargs):
context['has_pdf_render'] = HAS_PDF
context['completed_problem_ids'] = self.get_completed_problems()
context['attempted_problems'] = self.get_attempted_problems()
context['form'] = ProblemSubmitForm()

can_edit = self.object.is_editable_by(user)
context['can_edit_problem'] = can_edit
if user.is_authenticated:
tickets = self.object.tickets
context['default_lang'] = self.request.profile.language
if not can_edit:
tickets = tickets.filter(own_ticket_filter(user.profile.id))
context['has_tickets'] = tickets.exists()
Expand Down
55 changes: 51 additions & 4 deletions templates/problem/problem.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "common-content.html" %}
{% block content_media %}
{% include "comments/media-css.html" %}
{{ form.media.css }}
<style>
.title-state {
font-size: 2em;
Expand Down Expand Up @@ -34,18 +35,41 @@
min-width: 12.5em;
}

#problem-types, #allowed-langs, #available-judges {
#problem-types, #allowed-langs, #available-judges, #file-upload {
padding-top: 1em;
}

.problem-info-entry {
padding-top: 0.5em;
}

#file-upload-form > div {
margin-top: 5px;
}
</style>
{% endblock %}

{% block content_js_media %}
{{ form.media.js }}
{% include "comments/media-js.html" %}
<script>
$(document).ready(function () {
$("#file-upload-submit").click(function (event) {
const reader = new FileReader();
reader.addEventListener("load", function () {
const form = $(`<form style="display:none;" action="{{ url('problem_submit', problem.code) }}" method="post">
{% csrf_token %}
<textarea name="source" id="hidden-textarea-file-submit" />
<input name="language" value="${$("#id_language").val()}" />
</form>`);
$('body').append(form);
$('#hidden-textarea-file-submit').val(reader.result);
form.submit();
});
reader.readAsText($("#file-upload-input")[0].files[0]);
});
});
</script>
{% endblock %}

{% block title_row %}
Expand Down Expand Up @@ -98,7 +122,7 @@ <h2 style="color:#393630; display: inline-block">{{ title }}</h2>
{% if request.user.is_authenticated and request.in_contest and submission_limit %}
{% if submissions_left > 0 %}
<a href="{{ url('problem_submit', problem.code) }}" class="unselectable button full">
{{ _('Submit solution') }}
{{ _('Go to editor') }}
</a>
<div class="submissions-left">
{% trans trimmed counter=submissions_left %}
Expand All @@ -108,14 +132,37 @@ <h2 style="color:#393630; display: inline-block">{{ title }}</h2>
{% endtrans %}
</div>
{% else %}
<a class="unselectable button full disabled">{{ _('Submit solution') }}</a>
<a class="unselectable button full disabled">{{ _('Go to editor') }}</a>
<div class="no-submissions-left submissions-left">{{ _('0 submissions left') }}</div>
{% endif %}
{% else %}
<a href="{{ url('problem_submit', problem.code) }}" class="unselectable button full">
{{ _('Submit solution') }}
{{ _('Go to editor') }}
</a>
{% endif %}
{% if request.user.is_authenticated and (not request.in_contest or submission_limit) %}
<div id="file-upload">
<div class="toggle closed unselectable">
<i class="fa fa-chevron-right fa-fw"></i>Upload a file
</div>
<div style="display:none;" class="toggled" id="file-upload-form">
<div>
<input type="file" id="file-upload-input" name="file"/>
</div>
<div id="language-select">
<select id="id_language" name="language" class="full">
{% for lang in form.fields.language.queryset %}
<option value="{{ lang.id }}" {% if request.user.is_authenticated and lang.id == default_lang.id %}selected{% endif %}>{{ lang.name }}</option>
{% endfor %}
</select>
</div>
<div>
<input value="{{ _('Submit!') }}" id="file-upload-submit" class="unselectable button full"
{% if request.in_contest and submission_limit and submissions_left == 0 %}disabled{% endif %} />
</div>
</div>
</div>
{% endif %}

<hr style="padding-bottom: 0.3em">

Expand Down