lost track of changes...

This commit is contained in:
Ross
2023-01-09 09:52:09 +00:00
parent 9fc457c8a5
commit af52658e44
28 changed files with 469 additions and 118 deletions
+40 -5
View File
@@ -184,8 +184,11 @@ class ExamBase(models.Model):
def get_exam_name(self):
return self.name
def get_json_url(self):
return reverse("{}:exam_json".format(self.app_name), args=(self.pk,))
def get_json_url(self, cid=None, passcode=None):
if cid is None:
return reverse("{}:exam_json".format(self.app_name), args=(self.pk,))
else:
return reverse("{}:exam_json_cid".format(self.app_name), args=(self.pk,cid, passcode))
def get_question_index(self, question):
return list(self.exam_questions.all()).index(question)
@@ -200,17 +203,24 @@ class ExamBase(models.Model):
authors = [i for i in self.author.all()]
return authors
def check_cid_user(self, cid, passcode, request=None, user_id=None):
def check_cid_user(self, cid: int|None, passcode: str|None, request: HttpRequest|None=None, user_id: int|None=None, allow_authors: bool=True):
if request is not None and request.user.is_superuser:
return True
if not self.valid_cid_users.exists() and not self.valid_user_users.exists():
return True
if user_id is not None:
if allow_authors:
if self.author.filter(pk=user_id).exists():
return True
if not self.valid_cid_users.exists() and not self.valid_user_users.exists():
return False
# Start by checking if the logged in user can access
if user_id is not None:
if self.valid_user_users.filter(pk=user_id).exists():
return True
# Then test CID data
if self.valid_cid_users.exists():
cid_user = self.valid_cid_users.filter(cid=cid).first()
@@ -365,6 +375,24 @@ class ExamBase(models.Model):
#self.save()
return [True, ""]
class ExamUserStatus(models.Model):
datetime = models.DateTimeField(auto_now_add=True)
cid_user = models.ForeignKey("CidUser", blank=True, null=True, on_delete=models.SET_NULL)
user_user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.SET_NULL)
status = models.CharField(max_length=255)
extra = models.CharField(max_length=255)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
exam = GenericForeignKey("content_type", "object_id")
def __str__(self):
if self.cid_user:
user = self.cid_user.cid
else:
user = self.user_user.username
return f"{self.datetime}: {user} - {self.status} ({self.extra})"
class NoteType(models.Model):
note_type = models.CharField(max_length=200)
@@ -620,6 +648,13 @@ class CidUserExam(models.Model):
# TODO switch to json field?
results_emailed_status = models.CharField(max_length=255, blank=True)
def __str__(self) -> str:
if self.cid_user is None:
user = self.user_user.username
else:
user = self.cid_user.cid
return f"{user}: {self.start_time:%Y-%m-%d %H:%M} {self.end_time:%Y-%m-%d %H:%M}"
CID_GROUP_EXAMS = (
("SBAs", "sba_cid_user_groups"),
("Physics", "physics_cid_user_groups"),