Add ExamUserStatus logging for exam completion and start events
This commit is contained in:
+33
-1
@@ -1,7 +1,7 @@
|
||||
from reversion.views import RevisionMixin
|
||||
from generic.mixins import CheckCanEditMixin, SuperuserRequiredMixin
|
||||
from django.views.generic.detail import DetailView
|
||||
from generic.models import CidUser
|
||||
from generic.models import CidUser, ExamUserStatus, CidUserExam
|
||||
from sbas.forms import UserAnswerForm, ExamAuthorForm, ExamForm
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
@@ -306,6 +306,17 @@ def exam_complete(request, pk, cid=None, passcode=None):
|
||||
cid_user_exam = exam.get_or_create_cid_user_exam(cid=cid, user_user=request.user)
|
||||
|
||||
cid_user_exam.complete_exam()
|
||||
try:
|
||||
ct = ContentType.objects.get_for_model(exam)
|
||||
ExamUserStatus.objects.create(
|
||||
content_type=ct,
|
||||
object_id=exam.pk,
|
||||
cid_user_exam=cid_user_exam,
|
||||
status="completed",
|
||||
extra="sbas",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return HttpResponse("<div role='alert' class='alert alert-info'>Exam completed</div>")
|
||||
|
||||
@@ -366,8 +377,29 @@ def exam_take(request, pk: int, sk: int, cid: int = None, passcode: str = None):
|
||||
|
||||
exam.check_user_can_take(cid, passcode, request.user)
|
||||
|
||||
# log start only when a new CidUserExam is created
|
||||
content_type = ContentType.objects.get_for_model(exam)
|
||||
existing = False
|
||||
if cid is not None:
|
||||
cid_user_obj = CidUser.objects.filter(cid=cid).first()
|
||||
existing = CidUserExam.objects.filter(content_type=content_type, object_id=exam.pk, cid_user=cid_user_obj).exists()
|
||||
else:
|
||||
existing = CidUserExam.objects.filter(content_type=content_type, object_id=exam.pk, user_user=request.user).exists()
|
||||
|
||||
cid_user_exam = exam.get_or_create_cid_user_exam(cid = cid, user_user=request.user)
|
||||
|
||||
if not existing:
|
||||
try:
|
||||
ExamUserStatus.objects.create(
|
||||
content_type=content_type,
|
||||
object_id=exam.pk,
|
||||
cid_user_exam=cid_user_exam,
|
||||
status="started",
|
||||
extra="sbas",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
question = exam.get_questions()[sk]
|
||||
|
||||
exam_length = len(exam.exam_questions.all())
|
||||
|
||||
Reference in New Issue
Block a user