from django.shortcuts import render, get_object_or_404, redirect from django.views.decorators.csrf import csrf_exempt from django import forms # from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required, user_passes_test from django.contrib.auth.models import User from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic import ListView from django.db.models.functions import Lower from django.core.cache import cache from django.urls import reverse_lazy, reverse from django.http import Http404, JsonResponse from django.http import HttpResponseRedirect, HttpResponse from physics.models import CidUserAnswer as PhysicsCidUserAnswer from physics.models import Exam as PhysicsExam from anatomy.models import CidUserAnswer as AnatomyCidUserAnswer from anatomy.models import Exam as AnatomyExam @login_required def profile(request): user = request.user return render(request, "profile.html", {"user": user}) def cid_selector(request): return render( request, "cid_selector.html", ) def cid_scores(request, pk): #exam = get_object_or_404(Exam, pk=pk) # TODO:Need some kind of test for cid cid = pk #questions = exam.exam_questions.all() physics_answers = PhysicsCidUserAnswer.objects.filter( cid=cid) anatomy_answers = AnatomyCidUserAnswer.objects.filter( cid=cid) if not physics_answers and not anatomy_answers: raise Http404("cid not found") physics_exam_ids = physics_answers.values_list("exam").distinct() physics_exams = PhysicsExam.objects.filter(id__in=physics_exam_ids) anatomy_exam_ids = anatomy_answers.values_list("exam").distinct() anatomy_exams = AnatomyExam.objects.filter(id__in=anatomy_exam_ids) return render( request, "cid_scores.html", { "physics_exams": physics_exams, "anatomy_exams": anatomy_exams, "cid": cid, }, )