diff --git a/pt/views.py b/pt/views.py index b360bdc..28d2950 100644 --- a/pt/views.py +++ b/pt/views.py @@ -15,11 +15,15 @@ def compare(request): if "left" not in request.session: left_pic = random_pic() request.session["left"] = left_pic.id + request.session["left_count"] = 0 if "right" not in request.session: right_pic = random_pic() request.session["right"] = right_pic.id + request.session["right_count"] = 0 left_pic = models.Picture.objects.get(id=request.session["left"]) right_pic = models.Picture.objects.get(id=request.session["right"]) + request.session["left_count"] += 1 + request.session["right_count"] += 1 context = { "left": left_pic, "right": right_pic, @@ -48,6 +52,9 @@ def left_wins(request): right.elo -= adjust right.save() log.info("after: left=%f, right=%f", left.elo, right.elo) + log.info("counts: left=%d, right=%d", request.session["left_count"], request.session["right_count"]) + if request.session["left_count"] >= 5: + del request.session["left"] del request.session["right"] return HttpResponseRedirect(reverse('compare')) @@ -65,6 +72,9 @@ def right_wins(request): right.elo += adjust right.save() log.info("after: left=%f, right=%f", left.elo, right.elo) + log.info("counts: left=%d, right=%d", request.session["left_count"], request.session["right_count"]) + if request.session["right_count"] >= 5: + del request.session["right"] del request.session["left"] return HttpResponseRedirect(reverse('compare'))