Beispiel #1
0
def submit_view(request, problem_instance_id=None):
    if request.method == 'POST':
        form = SubmissionForm(request, request.POST, request.FILES)
        if form.is_valid():
            request.contest.controller.create_submission(
                request, form.cleaned_data['problem_instance'],
                form.cleaned_data)
            return redirect('my_submissions', contest_id=request.contest.id)
    else:
        initial = {}
        if problem_instance_id is not None:
            initial = {'problem_instance_id': int(problem_instance_id)}
        form = SubmissionForm(request, initial=initial)

    pis = form.get_problem_instances()
    submissions_left = {
        pi.id: pi.controller.get_submissions_left(request, pi)
        for pi in pis
    }
    return TemplateResponse(
        request,
        'contests/submit.html',
        {
            'form': form,
            'submissions_left': submissions_left
        },
    )
Beispiel #2
0
def submit_view(request):
    try:
        token = request.POST['token']
        current_token = SubmitServiceToken.objects.filter(token=token)
        if not current_token.exists():
            raise PermissionDenied('AUTHORIZATION_FAILED')
        request.user = current_token[0].user
        if not can_enter_contest(request):
            raise PermissionDenied('AUTHORIZATION_FAILED')
        task_name = request.POST['task']
        file_name, file_extension = os.path.splitext(
            request.FILES['file'].name)
        if task_name:
            file_name = task_name
        pi = match_problem(visible_problem_instances(request), file_name)
        if not pi:
            raise SubmitServiceException(
                'NO_SUCH_PROBLEM',
                ', '.join([
                    x.short_name for x in visible_problem_instances(request)
                ]),
            )

        lang_exts = get_allowed_languages_extensions(pi)
        if file_extension[1:] not in lang_exts:
            raise ValueError('UNSUPPORTED_EXTENSION')

        form = SubmissionForm(
            request,
            {
                'problem_instance_id': pi.id,
                'user': request.user,
                'kind': 'NORMAL'
            },
            request.FILES,
        )
        if not form.is_valid():
            raise SubmitServiceException('INVALID_SUBMISSION', form.errors)
        submission = request.contest.controller.create_submission(
            request, pi, form.cleaned_data)
        result_url = reverse(
            'submission',
            kwargs={
                'contest_id': request.contest.id,
                'submission_id': submission.id
            },
        )
        result = {'result_url': result_url, 'submission_id': submission.id}
    except SubmitServiceException as exception_info:
        result = {
            'error_code':
            exception_info.args[0],
            'error_data':
            exception_info.args[1] if len(exception_info.args) == 2 else '',
        }
    except Exception as e:
        result = {'error_code': 'UNKNOWN_ERROR', 'error_data': str(e)}
    return result
Beispiel #3
0
def submit_view(request):
    if request.method == 'POST':
        form = SubmissionForm(request, request.POST, request.FILES)
        if form.is_valid():
            request.contest.controller.create_submission(request,
                    form.cleaned_data['problem_instance'], form.cleaned_data)
            return redirect('my_submissions', contest_id=request.contest.id)
    else:
        form = SubmissionForm(request)
    return TemplateResponse(request, 'contests/submit.html', {'form': form})
Beispiel #4
0
def submit_view(request):
    if request.method == 'POST':
        form = SubmissionForm(request, request.POST, request.FILES)
        if form.is_valid():
            request.contest.controller.create_submission(request,
                    form.cleaned_data['problem_instance'], form.cleaned_data)
            return redirect('my_submissions', contest_id=request.contest.id)
    else:
        form = SubmissionForm(request)
    return TemplateResponse(request, 'contests/submit.html', {'form': form})
Beispiel #5
0
def testrun_submit_view(request, contest_id):
    if request.method == 'POST':
        form = SubmissionForm(request, request.POST, request.FILES,
                kind='TESTRUN', problem_filter=filter_testrun_problem_instances)
        if form.is_valid():
            request.contest.controller.create_testrun(request,
                    form.cleaned_data['problem_instance'], form.cleaned_data)
            return redirect('my_submissions', contest_id=contest_id)
    else:
        form = SubmissionForm(request, kind='TESTRUN',
                                problem_filter=filter_testrun_problem_instances)
    return TemplateResponse(request, 'testrun/submit.html', {'form': form})
Beispiel #6
0
def testrun_submit_view(request):
    if request.method == 'POST':
        form = SubmissionForm(
            request,
            request.POST,
            request.FILES,
            kind='TESTRUN',
            problem_filter=filter_testrun_problem_instances,
        )
        if form.is_valid():
            request.contest.controller.create_testrun(
                request, form.cleaned_data['problem_instance'],
                form.cleaned_data)
            return redirect('my_submissions', contest_id=request.contest.id)
    else:
        form = SubmissionForm(request,
                              kind='TESTRUN',
                              problem_filter=filter_testrun_problem_instances)

    problem_instances = filter_testrun_problem_instances(
        form.get_problem_instances())

    submissions_left = {
        pi.id: pi.controller.get_submissions_left(request, pi, 'TESTRUN')
        for pi in problem_instances
    }

    # Testrun time limits in seconds.
    time_limits = {
        pi.id: float(pi.controller.get_test_run_time_limit(pi)) / 1000
        for pi in problem_instances
    }

    # Testrun memory limits in MB.
    memory_limits = {
        pi.id: pi.controller.get_test_run_memory_limit(pi) / 1024
        for pi in problem_instances
    }

    return TemplateResponse(
        request,
        'testrun/submit.html',
        {
            'form': form,
            'submissions_left': submissions_left,
            'time_limits': time_limits,
            'memory_limits': memory_limits,
        },
    )
Beispiel #7
0
def testrun_submit_view(request):
    if request.method == 'POST':
        form = SubmissionForm(request, request.POST, request.FILES,
                kind='TESTRUN',
                problem_filter=filter_testrun_problem_instances)
        if form.is_valid():
            request.contest.controller.create_testrun(request,
                    form.cleaned_data['problem_instance'], form.cleaned_data)
            return redirect('my_submissions', contest_id=request.contest.id)
    else:
        form = SubmissionForm(request, kind='TESTRUN',
                              problem_filter=filter_testrun_problem_instances)
    submissions_left = {pi.id: pi.controller.get_submissions_left(request, pi, 'TESTRUN')
                        for pi in form.get_problem_instances()}
    return TemplateResponse(request, 'testrun/submit.html',
                            {'form': form, 'submissions_left': submissions_left})
Beispiel #8
0
def submit_view(request, problem_instance_id=None):
    if request.method == 'POST':
        form = SubmissionForm(request, request.POST, request.FILES)
        if form.is_valid():
            request.contest.controller.create_submission(request,
                    form.cleaned_data['problem_instance'], form.cleaned_data)
            return redirect('my_submissions', contest_id=request.contest.id)
    else:
        initial = {}
        if problem_instance_id is not None:
            initial = {'problem_instance_id': int(problem_instance_id)}
        form = SubmissionForm(request, initial=initial)
    submissions_left = {pi.id: pi.controller.get_submissions_left(request, pi)
         for pi in form.get_problem_instances()}
    return TemplateResponse(request, 'contests/submit.html',
                            {'form': form, 'submissions_left': submissions_left})
Beispiel #9
0
def testrun_submit_view(request):
    if request.method == 'POST':
        form = SubmissionForm(request,
                              request.POST,
                              request.FILES,
                              kind='TESTRUN',
                              problem_filter=filter_testrun_problem_instances)
        if form.is_valid():
            request.contest.controller.create_testrun(
                request, form.cleaned_data['problem_instance'],
                form.cleaned_data)
            return redirect('my_submissions', contest_id=request.contest.id)
    else:
        form = SubmissionForm(request,
                              kind='TESTRUN',
                              problem_filter=filter_testrun_problem_instances)
    return TemplateResponse(request, 'testrun/submit.html', {'form': form})
Beispiel #10
0
def submit_view(request):
    try:
        token = request.POST['token']
        current_token = SubmitServiceToken.objects.filter(token=token)
        if not current_token.exists():
            raise PermissionDenied('AUTHORIZATION_FAILED')
        request.user = current_token[0].user
        if not can_enter_contest(request):
            raise PermissionDenied('AUTHORIZATION_FAILED')
        task_name = request.POST['task']
        file_name, file_extension = \
            os.path.splitext(request.FILES['file'].name)
        if task_name:
            file_name = task_name
        pi = match_problem(visible_problem_instances(request), file_name)
        if not pi:
            raise SubmitServiceException('NO_SUCH_PROBLEM', ', '.join([
                    x.short_name for x in visible_problem_instances(request)]))

        lang_exts = sum(
            getattr(settings, 'SUBMITTABLE_EXTENSIONS', {}).values(), [])
        if file_extension[1:] not in lang_exts:
            raise ValueError('UNSUPPORTED_EXTENSION')

        form = SubmissionForm(request, {
            'problem_instance_id': pi.id,
            'user': request.user,
            'kind': 'NORMAL'
        }, request.FILES)
        if not form.is_valid():
            raise SubmitServiceException('INVALID_SUBMISSION', form.errors)
        submission = request.contest.controller \
            .create_submission(request, pi, form.cleaned_data)
        result_url = reverse('oioioi.contests.views.submission_view',
                                kwargs={'contest_id': request.contest.id,
                                'submission_id': submission.id})
        result = {'result_url': result_url, 'submission_id': submission.id}
    except SubmitServiceException as exception_info:
        result = {'error_code': exception_info.args[0],
                  'error_data': exception_info.args[1]
                  if len(exception_info.args) == 2 else ''}
    except StandardError as e:
        result = {'error_code': 'UNKNOWN_ERROR',
                  'error_data': str(e)}
    return result