def find_interview(request): context = {'username': request.session['username'], 'usertype': request.session['usertype']} if request.POST: if "send" in request.POST: choices_ = [x for x in request.POST if x.startswith("r")] choices__ = [] for x in choices_: choice = InterviewChoice.objects.get(pk=int(request.POST[x])) choice.pick = str(int(choice.pick) + 1) choice.save() choices__.append(request.POST.get(x)) intresult = InterviewResult(user=User.objects.get(username=request.session['username']), choice=choice) intresult.save() return redirect("/") else: group = request.POST.get("intertext") interviews, choices = [], [] checked = False for x in Interview.objects.all(): for y in InterviewResult.objects.all(): if y.user == User.objects.get(username=request.session['username']) and y.choice.interview == x: checked = True if x.group == group and x.visible and not checked: interviews.append(x) choices.append(x.interviewchoice_set) checked = False context["interviews"], context["choices"] = interviews, choices return render(request, "studtests/detail_int.html", context)
def get_res(request): checked = False choice = InterviewChoice.objects.get(pk=int(request.POST.get("id"))) choice.pick = str(int(choice.pick) + 1) choice.save() user = User.objects.get(pk=int(request.POST.get("user"))) try: result = InterviewResult.objects.get(choice=choice, user=user) checked = True except: checked = False if not checked: result = InterviewResult(choice=choice, user=user) result.save() return HttpResponse("done")