From 04dcb74e67b000b2601238b16cae47816c0d609e Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 29 Jan 2024 09:58:18 +0000 Subject: [PATCH] add exam collections --- .../migrations/0011_exam_exam_collection.py | 20 ++++++++++++++++++ .../0012_alter_exam_exam_collection.py | 20 ++++++++++++++++++ anatomy/models.py | 4 +++- atlas/models.py | 4 ++-- generic/migrations/0011_examcollection.py | 21 +++++++++++++++++++ generic/models.py | 10 +++++++-- longs/migrations/0015_exam_exam_collection.py | 20 ++++++++++++++++++ longs/models.py | 3 +++ .../migrations/0004_exam_exam_collection.py | 20 ++++++++++++++++++ .../0005_alter_exam_exam_collection.py | 20 ++++++++++++++++++ physics/models.py | 4 +++- .../migrations/0004_exam_exam_collection.py | 20 ++++++++++++++++++ rapids/models.py | 3 +++ sbas/migrations/0005_exam_exam_collection.py | 20 ++++++++++++++++++ sbas/models.py | 4 +++- 15 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 anatomy/migrations/0011_exam_exam_collection.py create mode 100644 anatomy/migrations/0012_alter_exam_exam_collection.py create mode 100644 generic/migrations/0011_examcollection.py create mode 100644 longs/migrations/0015_exam_exam_collection.py create mode 100644 physics/migrations/0004_exam_exam_collection.py create mode 100644 physics/migrations/0005_alter_exam_exam_collection.py create mode 100644 rapids/migrations/0004_exam_exam_collection.py create mode 100644 sbas/migrations/0005_exam_exam_collection.py diff --git a/anatomy/migrations/0011_exam_exam_collection.py b/anatomy/migrations/0011_exam_exam_collection.py new file mode 100644 index 00000000..17e83da1 --- /dev/null +++ b/anatomy/migrations/0011_exam_exam_collection.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:52 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0011_examcollection'), + ('anatomy', '0010_alter_anatomyquestion_answer_suggest_incorrect'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='generic.examcollection'), + ), + ] diff --git a/anatomy/migrations/0012_alter_exam_exam_collection.py b/anatomy/migrations/0012_alter_exam_exam_collection.py new file mode 100644 index 00000000..6584525b --- /dev/null +++ b/anatomy/migrations/0012_alter_exam_exam_collection.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:55 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0011_examcollection'), + ('anatomy', '0011_exam_exam_collection'), + ] + + operations = [ + migrations.AlterField( + model_name='exam', + name='exam_collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='anatomy_exams', to='generic.examcollection'), + ), + ] diff --git a/anatomy/models.py b/anatomy/models.py index f2348d7c..6ae5699f 100644 --- a/anatomy/models.py +++ b/anatomy/models.py @@ -17,7 +17,7 @@ from sortedm2m.fields import SortedManyToManyField import string -from generic.models import CidUser, CidUserGroup, ExamUserStatus, Examination, ExamBase, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup, Modality +from generic.models import CidUser, CidUserGroup, ExamCollection, ExamUserStatus, Examination, ExamBase, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup, Modality from atlas.models import Structure from collections import defaultdict @@ -404,6 +404,8 @@ class Exam(ExamBase): exam_user_status = GenericRelation(ExamUserStatus) + exam_collection = models.ForeignKey(ExamCollection, blank=True, null=True, on_delete=models.SET_NULL, related_name="anatomy_exams") + def get_exam_json(self, based=True): questions = self.exam_questions.all() diff --git a/atlas/models.py b/atlas/models.py index f0dccb76..d77d3413 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -44,7 +44,7 @@ from generic.models import ( CidUser, CidUserExam, CidUserGroup, - ExamCollectionGenericBase, + ExamOrCollectionGenericBase, Examination, # Condition, ExamBase, @@ -618,7 +618,7 @@ class Series(SeriesBase): return series_json -class CaseCollection(ExamCollectionGenericBase): +class CaseCollection(ExamOrCollectionGenericBase): app_name = "atlas" cases = models.ManyToManyField(Case, through="CaseDetail") diff --git a/generic/migrations/0011_examcollection.py b/generic/migrations/0011_examcollection.py new file mode 100644 index 00000000..36fa9ac6 --- /dev/null +++ b/generic/migrations/0011_examcollection.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0010_userprofile_site'), + ] + + operations = [ + migrations.CreateModel( + name='ExamCollection', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('date', models.DateField(blank=True, null=True)), + ], + ), + ] diff --git a/generic/models.py b/generic/models.py index 26411dda..268320ba 100644 --- a/generic/models.py +++ b/generic/models.py @@ -519,7 +519,7 @@ class SeriesBase(models.Model): pass -class ExamCollectionGenericBase(models.Model): +class ExamOrCollectionGenericBase(models.Model): """Holds functions that relate to both case and other exams e.g. user management @@ -734,7 +734,7 @@ class ExamCollectionGenericBase(models.Model): ) -class ExamBase(ExamCollectionGenericBase): +class ExamBase(ExamOrCollectionGenericBase): exam_mode = models.BooleanField( help_text="If an exam should be taken in exam mode (users results will be submited to the server for marking)", default=False, @@ -1517,3 +1517,9 @@ def create_user_profile(sender, instance, created, **kwargs): @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): instance.userprofile.save() + +class ExamCollection(models.Model): + name = models.CharField(max_length=255) + + date = models.DateField(blank=True,null=True) + diff --git a/longs/migrations/0015_exam_exam_collection.py b/longs/migrations/0015_exam_exam_collection.py new file mode 100644 index 00000000..198c3d6a --- /dev/null +++ b/longs/migrations/0015_exam_exam_collection.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:57 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0011_examcollection'), + ('longs', '0014_exam_stats_graph'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='longs_exams', to='generic.examcollection'), + ), + ] diff --git a/longs/models.py b/longs/models.py index 5df6dc5b..6cecd68f 100644 --- a/longs/models.py +++ b/longs/models.py @@ -28,6 +28,7 @@ from helpers.images import image_as_base64, pretty_print_dicom from generic.models import ( CidUser, CidUserGroup, + ExamCollection, ExamUserStatus, Examination, ExamBase, @@ -465,6 +466,8 @@ class Exam(ExamBase): exam_user_status = GenericRelation(ExamUserStatus) + exam_collection = models.ForeignKey(ExamCollection, blank=True, null=True, on_delete=models.SET_NULL, related_name="longs_exams") + def get_exam_question_json(self, question_id): q = get_object_or_404(Long, pk=question_id) diff --git a/physics/migrations/0004_exam_exam_collection.py b/physics/migrations/0004_exam_exam_collection.py new file mode 100644 index 00000000..8ca628d3 --- /dev/null +++ b/physics/migrations/0004_exam_exam_collection.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:55 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0011_examcollection'), + ('physics', '0003_exam_stats_graph'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rapids_exams', to='generic.examcollection'), + ), + ] diff --git a/physics/migrations/0005_alter_exam_exam_collection.py b/physics/migrations/0005_alter_exam_exam_collection.py new file mode 100644 index 00000000..e3a01654 --- /dev/null +++ b/physics/migrations/0005_alter_exam_exam_collection.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:57 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0011_examcollection'), + ('physics', '0004_exam_exam_collection'), + ] + + operations = [ + migrations.AlterField( + model_name='exam', + name='exam_collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='physics_exams', to='generic.examcollection'), + ), + ] diff --git a/physics/models.py b/physics/models.py index 644c3e7f..6525a836 100644 --- a/physics/models.py +++ b/physics/models.py @@ -12,7 +12,7 @@ from django.utils.translation import gettext_lazy as _ from sortedm2m.fields import SortedManyToManyField -from generic.models import CidUser, CidUserGroup, ExamBase, ExamUserStatus, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup +from generic.models import CidUser, CidUserGroup, ExamBase, ExamCollection, ExamUserStatus, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup import reversion @@ -182,6 +182,8 @@ class Exam(ExamBase): exam_user_status = GenericRelation(ExamUserStatus) + exam_collection = models.ForeignKey(ExamCollection, blank=True, null=True, on_delete=models.SET_NULL, related_name="physics_exams") + def get_take_url(self): return reverse("physics:exam_start", kwargs={"pk": self.pk}) diff --git a/rapids/migrations/0004_exam_exam_collection.py b/rapids/migrations/0004_exam_exam_collection.py new file mode 100644 index 00000000..a18b8cec --- /dev/null +++ b/rapids/migrations/0004_exam_exam_collection.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:57 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0011_examcollection'), + ('rapids', '0003_exam_stats_graph'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rapids_exams', to='generic.examcollection'), + ), + ] diff --git a/rapids/models.py b/rapids/models.py index 2addd7d7..738a56ce 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -28,6 +28,7 @@ from django.contrib.contenttypes.fields import GenericRelation from generic.models import ( CidUser, CidUserGroup, + ExamCollection, ExamUserStatus, QuestionBase, Site, @@ -648,6 +649,8 @@ class Exam(ExamBase): exam_user_status = GenericRelation(ExamUserStatus) + exam_collection = models.ForeignKey(ExamCollection, blank=True, null=True, on_delete=models.SET_NULL, related_name="rapids_exams") + def get_normal_abnormal_breakdown(self): # Inefficient but more extendible questions = self.exam_questions.all() diff --git a/sbas/migrations/0005_exam_exam_collection.py b/sbas/migrations/0005_exam_exam_collection.py new file mode 100644 index 00000000..4f6aefaf --- /dev/null +++ b/sbas/migrations/0005_exam_exam_collection.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.4 on 2024-01-29 09:57 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('generic', '0011_examcollection'), + ('sbas', '0004_exam_stats_graph'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sbas_exams', to='generic.examcollection'), + ), + ] diff --git a/sbas/models.py b/sbas/models.py index fa1e2eab..3ca7315d 100644 --- a/sbas/models.py +++ b/sbas/models.py @@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _ from sortedm2m.fields import SortedManyToManyField -from generic.models import CidUser, CidUserGroup, ExamBase, ExamUserStatus, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup +from generic.models import CidUser, CidUserGroup, ExamBase, ExamCollection, ExamUserStatus, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup import reversion @@ -198,6 +198,8 @@ class Exam(ExamBase): exam_user_status = GenericRelation(ExamUserStatus) + exam_collection = models.ForeignKey(ExamCollection, blank=True, null=True, on_delete=models.SET_NULL, related_name="sbas_exams") + def get_take_url(self): return reverse("sbas:exam_start", kwargs={"pk": self.pk})