Esempio n. 1
0
def show_submission_source_view(request, contest_id, submission_id):
    submission = get_object_or_404(ProgramSubmission, id=submission_id)
    if contest_id != submission.problem_instance.contest_id:
        raise Http404
    check_submission_access(request, submission)
    raw_source = submission.source_file.read()
    filename = submission.source_file.file.name
    is_source_safe = True
    try:
        lexer = guess_lexer_for_filename(
            filename,
            raw_source
        )
        formatter = HtmlFormatter(linenos=True, cssclass='syntax-highlight')
        formatted_source = highlight(raw_source, lexer, formatter)
        formatted_source_css = HtmlFormatter().get_style_defs('.syntax-highlight')
    except ClassNotFound:
        formatted_source = raw_source
        formatted_source_css = ''
        is_source_safe = False
    return TemplateResponse(request, 'programs/source.html', {
        'source': formatted_source,
        'css': formatted_source_css,
        'is_source_safe': is_source_safe
    })
Esempio n. 2
0
def show_submission_source_view(request, contest_id, submission_id):
    submission = get_object_or_404(ProgramSubmission, id=submission_id)
    if contest_id != submission.problem_instance.contest_id:
        raise Http404
    check_submission_access(request, submission)
    response = HttpResponse(submission.source_file.read(),
                            content_type='text/plain')
    response['Content-Disposition'] = 'inline'
    return response
Esempio n. 3
0
def show_submission_source_view(request, contest_id, submission_id):
    submission = get_object_or_404(ProgramSubmission, id=submission_id)
    if contest_id != submission.problem_instance.contest_id:
        raise Http404
    check_submission_access(request, submission)
    response = HttpResponse(submission.source_file.read(),
            content_type='text/plain')
    response['Content-Disposition'] = 'inline'
    return response
Esempio n. 4
0
def download_submission_source_view(request, contest_id, submission_id):
    submission = get_object_or_404(ProgramSubmission, id=submission_id)
    if contest_id != submission.problem_instance.contest_id:
        raise Http404
    check_submission_access(request, submission)
    return stream_file(submission.source_file)
Esempio n. 5
0
def download_submission_source_view(request, contest_id, submission_id):
    submission = get_object_or_404(ProgramSubmission, id=submission_id)
    if contest_id != submission.problem_instance.contest_id:
        raise Http404
    check_submission_access(request, submission)
    return stream_file(submission.source_file)