Add manual submission flag to CidUserExam and improve logging for exam completion
This commit is contained in:
+3
-20
@@ -69,6 +69,8 @@ from .decorators import (
|
||||
user_is_exam_author_or_physics_checker,
|
||||
)
|
||||
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class AuthorOrCheckerRequiredMixin(object):
|
||||
def get_object(self, *args, **kwargs):
|
||||
@@ -158,6 +160,7 @@ def exam_complete(request, pk, cid=None, passcode=None):
|
||||
extra="physics",
|
||||
)
|
||||
except Exception:
|
||||
logger.error("Failed to log exam completion status")
|
||||
# avoid crashing the user flow if logging fails
|
||||
pass
|
||||
|
||||
@@ -190,28 +193,8 @@ def exam_take_overview(request, pk, cid=None, passcode=None):
|
||||
else:
|
||||
question_answer_tuples.append((q, None))
|
||||
|
||||
# detect whether a CidUserExam already exists so we only log the initial start once
|
||||
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="physics",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
||||
Reference in New Issue
Block a user