Add CID user support in collection history and reset answers functionality

This commit is contained in:
Ross
2025-10-13 11:28:07 +01:00
parent fa08f9cf76
commit 32d8430f94
8 changed files with 222 additions and 58 deletions
+31 -1
View File
@@ -905,9 +905,10 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
def get_question_user_user_answer(self, question_index, user):
raise NotImplementedError
def get_cid_user_exams(
def get_cid_and_user_exams(
self, cid_user: Optional["CidUser"] = None, user_user: User | None = None
) -> "CidUserExam":
"""Returns a queryset of CidUserExam for this exam/collection"""
content_type = ContentType.objects.get_for_model(self)
if cid_user is None and user_user is None:
return CidUserExam.objects.filter(
@@ -924,6 +925,35 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
content_type=content_type, object_id=self.pk, user_user=user_user
)
def get_cid_exams(self, cid_user: Optional["CidUser"]= None) -> "CidUserExam":
"""Returns a queryset of CidUserExam for this exam/collection"""
content_type = ContentType.objects.get_for_model(self)
if cid_user is None:
# Only return pure CID entries (cid_user set, user_user null)
return CidUserExam.objects.filter(
content_type=content_type,
object_id=self.pk,
cid_user__isnull=False,
user_user__isnull=True,
)
return CidUserExam.objects.filter(
content_type=content_type, object_id=self.pk, cid_user=cid_user
)
def get_user_exams(self, user_user: Optional[User] = None) -> "CidUserExam":
"""Returns a queryset of CidUserExam for this exam/collection"""
content_type = ContentType.objects.get_for_model(self)
if user_user is None:
return CidUserExam.objects.filter(
content_type=content_type, object_id=self.pk, user_user__isnull=False, cid_user__isnull=True
)
return CidUserExam.objects.filter(
content_type=content_type, object_id=self.pk, user_user=user_user
)
def clone_model(self):
M2M_fields = (
"exam_questions",