Add download AC submissions
This commit is contained in:
parent
e8ef46ffcf
commit
859c8f62ed
3 changed files with 27 additions and 1 deletions
|
@ -119,6 +119,7 @@ urlpatterns = [
|
|||
url(r'^/pdf$', problem.ProblemPdfView.as_view(), name='problem_pdf'),
|
||||
url(r'^/pdf/(?P<language>[a-z-]+)$', problem.ProblemPdfView.as_view(), name='problem_pdf'),
|
||||
url(r'^/clone', problem.ProblemClone.as_view(), name='problem_clone'),
|
||||
url(r'^/downloadAC$', problem.download_submissions, name='download_submissions'),
|
||||
url(r'^/submit$', problem.problem_submit, name='problem_submit'),
|
||||
url(r'^/resubmit/(?P<submission>\d+)$', problem.problem_submit, name='problem_submit'),
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import shutil
|
|||
from datetime import timedelta
|
||||
from operator import itemgetter
|
||||
from random import randrange
|
||||
import zipfile, tempfile
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
@ -677,3 +678,21 @@ class ProblemClone(ProblemMixin, PermissionRequiredMixin, TitleMixin, SingleObje
|
|||
problem.types.set(types)
|
||||
|
||||
return HttpResponseRedirect(reverse('admin:judge_problem_change', args=(problem.id,)))
|
||||
|
||||
|
||||
def download_submissions(request, problem):
|
||||
submissions = Submission.objects.filter(problem__code=problem, result='AC')
|
||||
|
||||
with tempfile.SpooledTemporaryFile() as tmp:
|
||||
with zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED) as archive:
|
||||
for submission in submissions:
|
||||
file_name = str(submission.id) + '.' + str(submission.language.key)
|
||||
archive.writestr(file_name, submission.source.source)
|
||||
|
||||
# Reset file pointer
|
||||
tmp.seek(0)
|
||||
|
||||
# Write file data to response
|
||||
response = HttpResponse(tmp.read(), content_type='application/x-zip-compressed')
|
||||
response['Content-Disposition'] = 'attachment; filename="%s"' % (str(problem) + '_submissions.zip')
|
||||
return response
|
|
@ -126,6 +126,12 @@
|
|||
{% endif %}
|
||||
<div><a href="{{ url('chronological_submissions', problem.code) }}">{{ _('All submissions') }}</a></div>
|
||||
<div><a href="{{ url('ranked_submissions', problem.code) }}">{{ _('Best submissions') }}</a></div>
|
||||
{% if request.user.is_superuser %}
|
||||
<div>
|
||||
<a href="{{ url('download_submissions', problem.code) }}"> {{ _('Download AC submissions') }} </a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if editorial and editorial.is_public and
|
||||
not (request.user.is_authenticated and request.profile.current_contest) %}
|
||||
<hr>
|
||||
|
|
Loading…
Reference in a new issue