Beispiel #1
0
def olimpiada_check(request):
    if request.is_ajax():
        true_count, ball, true_problems, cb_result = (0, 0, [], '')
        for k in request.GET.keys():
            problem = get_object_or_404(Problem, pk=int(k[6:]))
            answer = request.GET[k]
            if answer == problem.answer:
                true_problems.append(problem)
                true_count += 1
                ball += 7
            cat = problem.category.slug
        if request.user.is_authenticated():
            category = get_object_or_404(Category, slug=cat)
            try:
                oldres = request.user.userprogress.challenge_best.get(category=category)
                if oldres.result < ball:
                    oldres.result = ball
                    oldres.save()
            except:
                bestres = ChallengeResult(category=category,result=ball)
                bestres.save()
                request.user.userprogress.challenge_best.add(bestres)
            for cb in request.user.userprogress.challenge_best.all():
                if category == cb.category:
                    cb_result = cb.result
                    break
        return render_to_response('challenge/_olimpiada_res.html', {'true_count': true_count,
                                                                  'ball': ball,
                                                                  'true_problems': true_problems,
                                                                  'cat': cat,
                                                                  'cb_result': cb_result})
    else:
        raise Http404
Beispiel #2
0
def kenguru_check(request):
    if request.is_ajax():
        true_count, true_3, true_4, true_5, ball, true_problems, cb_result = (0, 0, 0, 0, 0, [], '')
        for k in request.POST.keys():
            if k == 'csrfmiddlewaretoken': continue
            answer = get_object_or_404(Variant, pk=int(request.POST[k]))
            if answer.tru:
                true_problems.append(answer.pro.pk)
                true_count += 1
                if answer.pro.slogn == 1:
                    true_3 += 1
                    ball += 3
                elif answer.pro.slogn == 2:
                    true_4 += 1
                    ball += 4
                elif answer.pro.slogn == 3:
                    true_5 += 1
                    ball += 5
            cat = answer.pro.category.slug
        if request.user.is_authenticated():
            category = get_object_or_404(Category, slug=cat)
            for cb in request.user.userprogress.challenge_best.all():
                if category == cb.category:
                    cb_result = cb.result
                    break
            try:
                oldres = request.user.userprogress.challenge_best.get(category=category)
                if oldres.result < ball:
                    oldres.result = ball
                    oldres.save()
            except:
                bestres = ChallengeResult(category=category,result=ball)
                bestres.save()
                request.user.userprogress.challenge_best.add(bestres)
        return render_to_response('challenge/_kenguru_res.html', {'true_count': true_count,
                                                                  'true_3': true_3,
                                                                  'true_4': true_4,
                                                                  'true_5': true_5,
                                                                  'ball': ball,
                                                                  'true_problems': true_problems,
                                                                  'cat': cat,
                                                                  'cb_result': cb_result})
    else:
        raise Http404