예제 #1
0
파일: jury.py 프로젝트: WISVCH/szp4
def clarification(request):
    if request.method == 'POST':
        if request.POST['team'] != "global":
            teamlist = [Team.objects.get(id=request.POST['team'])]
        else:
            teamlist = Team.objects.all()

        if request.POST['problem'] != "General":
            problem = Problem.objects.get(letter=request.POST['problem'])
        else:
            problem = None

        for team in teamlist:
            clar = Clar()
            clar.problem = problem
            clar.subject = request.POST['subject']
            clar.message = request.POST['message']
            clar.receiver = team
            clar.read = False
            clar.save()

        sentclar = Sentclar()
        sentclar.problem = problem
        sentclar.subject = request.POST['subject']
        sentclar.message = request.POST['message']
        if request.POST['team'] != "global":
            sentclar.receiver = team
        sentclar.save()

        return HttpResponseRedirect('/jury/clarification/sent/%s/' % sentclar.id)

    problemlist = Problem.objects.order_by("letter")
    teamlist = Team.objects.order_by("name")

    total_sent = Sentclar.objects.count()
    total_general = Clarreq.objects.filter(problem=None).count()
    total_general_unhandled = Clarreq.objects.filter(problem=None).filter(dealt_with=False).count()

    total = total_general
    total_unhandled = total_general_unhandled

    prob_clarreqs = []
    for problem in problemlist:
        num = Clarreq.objects.filter(problem=problem).count()
        total += num
        unhandled = Clarreq.objects.filter(problem=problem).filter(dealt_with=False).count()
        total_unhandled += unhandled
        row = {"num": num,
               "unhandled": unhandled,
               "problem": problem}
        prob_clarreqs.append(row)

    return render_to_response('jury_clarification.html',
                              {"problemlist": problemlist, "teamlist": teamlist, 'total_sent': total_sent,
                               "total": total, "total_unhandled": total_unhandled,
                               "total_general": total_general, "total_general_unhandled": total_general_unhandled,
                               "prob_clarreqs": prob_clarreqs},
                              context_instance=RequestContext(request))
예제 #2
0
파일: jury.py 프로젝트: WISVCH/szp4
def clarification_reply(request, which):
    if request.method == 'POST':
        clarreq = Clarreq.objects.get(id=which)

        clar = Clar()
        clar.problem = clarreq.problem
        clar.subject = request.POST['subject']
        clar.message = request.POST['message']
        clar.receiver = clarreq.sender
        clar.read = False
        clar.save()

        sentclar = Sentclar()
        sentclar.problem = clarreq.problem
        sentclar.subject = request.POST['subject']
        sentclar.message = request.POST['message']
        sentclar.receiver = clarreq.sender
        sentclar.save()

        clarreq.dealt_with = True
        clarreq.save()

        return HttpResponseRedirect('/jury/clarification/sent/%s/' % sentclar.id)

    contest = Contest.objects.get()
    clarreq = Clarreq.objects.get(id=which)

    reply = {"to": clarreq.sender,
             "subject": "Re: " + clarreq.subject}

    if clarreq.problem:
        reply["problem"] = clarreq.problem
    else:
        reply["problem"] = "General"

    message = clarreq.sender.name + " wrote:\n"
    for line in clarreq.message.splitlines(True):
        message += "> "
        message += line

    message += "\n\nPlease read the problem specification more carefully."

    reply["message"] = message

    clars = Clarreq.objects.filter(problem=clarreq.problem).order_by("-timestamp")
    clarlist = []
    for c in clars:
        row = {"time": gettime(c.timestamp, contest), "subject": c.subject}
        row["url"] = c.id
        row["unhandled"] = not c.dealt_with
        row["from"] = c.sender.name
        clarlist.append(row)

    return render_to_response('jury_clarification_reply.html',
                              {"reply": reply, "clarlist": clarlist},
                              context_instance=RequestContext(request))