allow adding markers and authors to exams in collections
This commit is contained in:
@@ -882,6 +882,12 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
|
||||
|
||||
return cloned_model
|
||||
|
||||
def add_markers(self, users):
|
||||
self.markers.add(*users)
|
||||
|
||||
def add_marker(self, user):
|
||||
self.markers.add(user)
|
||||
|
||||
|
||||
class ExamBase(ExamOrCollectionGenericBase):
|
||||
exam_mode = models.BooleanField(
|
||||
@@ -1747,6 +1753,43 @@ class ExamCollection(models.Model, AuthorMixin):
|
||||
def get_absolute_url(self):
|
||||
return reverse("generic:examcollection_detail", kwargs={"pk": self.pk})
|
||||
|
||||
def get_exams(self):
|
||||
return {
|
||||
"anatomy": self.anatomy_exams.filter(archive=False),
|
||||
"longs": self.longs_exams.filter(archive=False),
|
||||
"physics": self.physics_exams.filter(archive=False),
|
||||
"rapids": self.rapids_exams.filter(archive=False),
|
||||
"sbas": self.sbas_exams.filter(archive=False),
|
||||
}
|
||||
|
||||
def add_author_to_exams(self, users, exam_types: None | list[str] =None):
|
||||
|
||||
for exam_type, exams in self.get_exams().items():
|
||||
if exam_types is None:
|
||||
pass
|
||||
elif exam_type not in exam_types:
|
||||
continue
|
||||
else:
|
||||
raise ValueError(f"Invalid exam type {exam_type}")
|
||||
|
||||
for exam in exams:
|
||||
exam.add_authors(users)
|
||||
#return True
|
||||
|
||||
def add_marker_to_exams(self, users, exam_types: None | list[str] =None):
|
||||
|
||||
for exam_type, exams in self.get_exams().items():
|
||||
if exam_types is None:
|
||||
pass
|
||||
elif exam_type not in exam_types:
|
||||
continue
|
||||
else:
|
||||
pass
|
||||
|
||||
for exam in exams:
|
||||
exam.add_markers(users)
|
||||
#return True
|
||||
|
||||
|
||||
#class Presentation(models.Model, AuthorMixin):
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user