Beispiel #1
0
def submission_changeresult(request, number):
    # FIXME: Make a django form for this.
    contest = Contest.objects.get()
    submission = Submission.objects.get(id=number)
    if request.method == 'POST':
        if "change" in request.POST:
            result = submission.result
            if submission.result is None:
                result = Result()
                comment = File(content="Manual judgement made by " + request.user.username)
                comment.save()
                result.compiler_output_file = comment

            result.judgement = request.POST["judgement"]
            result.save()

            if submission.result is None:
                submission.status = "CHECKED"
                submission.result = result
                submission.save()

            team = submission.team
            team.new_results = True
            team.save()

            Contest.objects.get().save()  # Updates 'resulttime'
        elif "rejudge" in request.POST:
            submission.autojudge = None
            submission.result = None
            submission.status = "NEW"
            submission.save()

        return HttpResponseRedirect('/jury/submission/%s/' % number)

    time = gettime(submission.timestamp, contest)

    try:
        result = submission.result
        judgement = result.judgement
        if result.verified_by:
            verified_by = result.verified_by.username
        else:
            verified_by = None
    except (ObjectDoesNotExist, AttributeError):
        judgement = "Pending..."
        verified_by = None

    judgementlist = []
    for j in Result.JUDGEMENT_CHOICES:
        if judgement == j[0]:
            judgementlist.append({"name": j[0], "selected": True})
        else:
            judgementlist.append({"name": j[0], "selected": False})

    return render_to_response('jury_submission_changeresult.html',
                              {'time': time, 'submission': submission,
                               'judgement': judgement, 'verified_by': verified_by,
                               'judgementlist': judgementlist},
                              context_instance=RequestContext(request))
Beispiel #2
0
def submitscript(request):
    ip_address = request.META['REMOTE_ADDR']
    user = authenticate(ip_address=ip_address)
    if user is not None and user.is_active:
        response = HttpResponse()

        if not 'problem' in request.POST or not 'compiler' in request.POST or not 'submission' in request.POST or not 'filename' in request.POST:
            response.write("Missing POST variables")
            return response
        try:
            problem = Problem.objects.get(letter=request.POST['problem'])
        except:
            response.write("ERROR: Invalid problem")
            return response

        try:
            compiler = Compiler.objects.get(id=request.POST['compiler'])
        except:
            response.write("ERROR: Invalid compiler")
            return response

        profile = user.get_profile()

        if not profile.is_judge:
            contest = Contest.objects.get()
            if contest.status != "RUNNING" and contest.status != "NOINFO":
                response.write("ERROR: Contest is not running.")
                return response
            if Submission.objects.filter(team=profile.team, problem=problem, result__judgement__exact="ACCEPTED").count():
                response.write("ERROR: A submission for this problem has been accepted already.")
                return response

        submission = Submission()
        submission.status = "NEW"
        submission.team = profile.team

        submission.problem = problem
        submission.compiler = compiler

        submission.file_name = request.POST['filename']
        file = File()
        file.content = request.POST['submission']
        file.save()
        submission.file = file
        submission.save()

        response.write("Submission successful")
        return response
    else:
        return HttpResponseRedirect('/look/')
Beispiel #3
0
def submission(request, problem=None):
    profile = request.user.get_profile()
    contest = Contest.objects.get()
    if request.method == 'POST':
        form = SubmitForm(request.POST, request.FILES, request=request)
        if form.is_valid():
            # TODO: Check whether extension is correct.
            submission = Submission()
            submission.status = "NEW"
            submission.team = profile.team

            submission.problem = form.cleaned_data['problem']
            submission.compiler = form.cleaned_data['compiler']

            submission.file_name = request.FILES['file'].name
            file = File()
            content = request.FILES['file'].read()
            try:
                file.content = content.decode("utf-8")
            except UnicodeError:
                file.content = content.decode("iso8859-1")

            file.save()
            submission.file = file
            submission.save()

            return HttpResponseRedirect('/team/submission/')

    else:
        form = SubmitForm()

    profile.team.new_results = False
    profile.team.save()

    submissions = Submission.objects.filter(team=profile.team).order_by("-timestamp")

    result_list = []

    for s in submissions:
        try:
            judgement = s.result.judgement
        except AttributeError:
            judgement = "Pending..."

        r = {'time': gettime(s.timestamp, contest), 'problem': s.problem, 'judgement': judgement}
        result_list.append(r)

    return render_to_response('team_submission.html',
                              {"profile": profile, 'form': form, 'results': result_list},
                              context_instance=RequestContext(request))
Beispiel #4
0
 def run(self, args):
     problem = Problem()
     problem.letter = args.letter
     problem.timelimit = args.timelimit
     problem.name = args.name
     problem.colour = args.colour
     problem.in_file_name = os.path.basename(args.infile.name)
     problem.out_file_name = os.path.basename(args.outfile.name)
     problem.check_script_file_name = os.path.basename(args.checkscript.name)
     in_file = File(content=args.infile.read())
     in_file.save()
     problem.in_file = in_file
     out_file = File(content=args.outfile.read())
     out_file.save()
     problem.out_file = out_file
     check_script = File(content=args.checkscript.read())
     check_script.save()
     problem.check_script_file = check_script
     problem.save()
     print 'Added problem %s' % problem
     Contest.objects.get().save()  # Updates 'resulttime'
Beispiel #5
0
sys.path.insert(0, os.path.normpath(sys.path[0] + "/.."))

from django.core.management import setup_environ
import settings

setup_environ(settings)

from szp.models import File
from django.db import connection, transaction

dir = os.path.join(os.getcwd(), "szp-files")
max_file_id = 0

for file in os.listdir(dir):
    print "Importing file %s" % file

    file_name = os.path.join(dir, file)
    fp = open(file_name, "r")
    file_contents = fp.read()
    fp.close()

    file_id = int(file)
    max_file_id = file_id if file_id > max_file_id else max_file_id

    db_file = File(id=file_id, content=file_contents)
    db_file.save()

cursor = connection.cursor()
cursor.execute("ALTER SEQUENCE public.szp_file_id_seq RESTART WITH %s", [max_file_id + 1])
transaction.commit_unless_managed()
Beispiel #6
0
def uploadresult(submission, judgement, compiler_output, submission_output=None, autojudge_comment=None, check_output=None):
    result = Result()
    result.judgement = judgement
    result.judged_by = autojudge

    compiler_output_file = File(content=compiler_output)
    compiler_output_file.save()
    result.compiler_output_file = compiler_output_file

    if submission_output:
        submission_output_file = File()
        try:
            submission_output_file.content = submission_output.decode("utf-8")
        except UnicodeError:
            submission_output_file.content = submission_output.decode("iso8859-1")
        submission_output_file.save()
        result.submission_output_file = submission_output_file

    if autojudge_comment:
        autojudge_comment_file = File(content=autojudge_comment)
        autojudge_comment_file.save()
        result.autojudge_comment_file = autojudge_comment_file

    if check_output:
        check_output_file = File()
        try:
            check_output_file.content = check_output.decode("utf-8")
        except UnicodeError:
            check_output_file.content = check_output.decode("iso8859-1")
        check_output_file.save()
        result.check_output_file = check_output_file

    result.save()
    submission.status = "CHECKED"
    submission.result = result
    submission.save()

    Contest.objects.get().save()  # Updates 'resulttime'

    team = submission.team
    team.new_results = True
    team.save()