migrate rapids
This commit is contained in:
@@ -13,8 +13,6 @@ from django.urls import reverse
|
|||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from sortedm2m.fields import SortedManyToManyField
|
|
||||||
|
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from generic.models import CidUser, CidUserGroup, ExamCollection, ExamUserStatus, Examination, ExamBase, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup, Modality
|
from generic.models import CidUser, CidUserGroup, ExamCollection, ExamUserStatus, Examination, ExamBase, QuestionBase, QuestionNote, UserAnswerBase, UserUserGroup, Modality
|
||||||
@@ -374,9 +372,6 @@ class ExamQuestionDetail(models.Model):
|
|||||||
class Exam(ExamBase):
|
class Exam(ExamBase):
|
||||||
app_name = "anatomy"
|
app_name = "anatomy"
|
||||||
|
|
||||||
#exam_questions = SortedManyToManyField(
|
|
||||||
# AnatomyQuestion, related_name="exams", blank="true"
|
|
||||||
#)
|
|
||||||
exam_questions = models.ManyToManyField("AnatomyQuestion", through=ExamQuestionDetail, related_name="exams")
|
exam_questions = models.ManyToManyField("AnatomyQuestion", through=ExamQuestionDetail, related_name="exams")
|
||||||
time_limit = models.IntegerField(
|
time_limit = models.IntegerField(
|
||||||
help_text="Exam time limit (in seconds)", default=5400
|
help_text="Exam time limit (in seconds)", default=5400
|
||||||
|
|||||||
+10
-4
@@ -86,11 +86,11 @@ from .models import (
|
|||||||
get_next_cid,
|
get_next_cid,
|
||||||
)
|
)
|
||||||
|
|
||||||
from rapids.models import Rapid as RapidQuestion, RapidImage
|
from rapids.models import Rapid as RapidQuestion, ExamQuestionDetail as RapidsExamQuestionDetail
|
||||||
from rapids.models import Exam as RapidsExam
|
from rapids.models import Exam as RapidsExam
|
||||||
from longs.models import Long as LongQuestion, LongSeries
|
from longs.models import Long as LongQuestion, LongSeries
|
||||||
from longs.models import Exam as LongsExam
|
from longs.models import Exam as LongsExam
|
||||||
from anatomy.models import AnatomyQuestion as AnatomyQuestion, ExamQuestionDetail
|
from anatomy.models import AnatomyQuestion as AnatomyQuestion, ExamQuestionDetail as AnatomyExamQuestionDetail
|
||||||
from anatomy.models import Exam as AnatomyExam
|
from anatomy.models import Exam as AnatomyExam
|
||||||
from sbas.models import Question as SbasQuestion
|
from sbas.models import Question as SbasQuestion
|
||||||
from sbas.models import Exam as SbasExam
|
from sbas.models import Exam as SbasExam
|
||||||
@@ -859,7 +859,8 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
to_attr="prefetched_primary_answer"
|
to_attr="prefetched_primary_answer"
|
||||||
# queryset=self.Answer.objects.filter(),
|
# queryset=self.Answer.objects.filter(),
|
||||||
),
|
),
|
||||||
).order_by("examquestiondetail__sort_order")
|
)
|
||||||
|
.order_by("examquestiondetail__sort_order")
|
||||||
)
|
)
|
||||||
elif self.app_name == "longs":
|
elif self.app_name == "longs":
|
||||||
questions = (
|
questions = (
|
||||||
@@ -900,6 +901,7 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
"examination",
|
"examination",
|
||||||
"author",
|
"author",
|
||||||
)
|
)
|
||||||
|
.order_by("examquestiondetail__sort_order")
|
||||||
)
|
)
|
||||||
# questions = (
|
# questions = (
|
||||||
# exam.exam_questions.select_related()
|
# exam.exam_questions.select_related()
|
||||||
@@ -1219,9 +1221,13 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
for n, question in enumerate(objects):
|
for n, question in enumerate(objects):
|
||||||
match self.app_name:
|
match self.app_name:
|
||||||
case "anatomy":
|
case "anatomy":
|
||||||
question_detail = ExamQuestionDetail.objects.get(
|
question_detail = AnatomyExamQuestionDetail.objects.get(
|
||||||
anatomyquestion=question, exam=exam
|
anatomyquestion=question, exam=exam
|
||||||
)
|
)
|
||||||
|
case "rapids":
|
||||||
|
question_detail = RapidsExamQuestionDetail.objects.get(
|
||||||
|
rapid=question, exam=exam
|
||||||
|
)
|
||||||
case _:
|
case _:
|
||||||
data = {"status": "error"}
|
data = {"status": "error"}
|
||||||
return JsonResponse(data, status=200)
|
return JsonResponse(data, status=200)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# Generated by Django 4.1.4 on 2024-02-17 22:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('rapids', '0005_rename_exam_collection_exam_examcollection'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ExamQuestionDetail',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('sort_order', models.IntegerField(default=1000)),
|
||||||
|
('exam', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rapids.exam')),
|
||||||
|
('rapid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rapids.rapid')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'ordering': ('sort_order',),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
"""INSERT INTO rapids_examquestiondetail
|
||||||
|
SELECT * FROM rapids_exam_exam_questions;"""
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.1.4 on 2024-02-17 22:57
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('rapids', '0006_examquestiondetail'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='exam',
|
||||||
|
name='exam_questions',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='exam',
|
||||||
|
name='exam_questions',
|
||||||
|
field=models.ManyToManyField(related_name='exams', through='rapids.ExamQuestionDetail', to='rapids.rapid'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+10
-1
@@ -601,12 +601,21 @@ class RapidCreationDefault(models.Model):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("rapids:rapid_create")
|
return reverse("rapids:rapid_create")
|
||||||
|
|
||||||
|
class ExamQuestionDetail(models.Model):
|
||||||
|
exam = models.ForeignKey("Exam", on_delete=models.CASCADE)
|
||||||
|
rapid = models.ForeignKey(Rapid, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
sort_order = models.IntegerField(default=1000)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ("sort_order",)
|
||||||
|
|
||||||
# @reversion.register
|
# @reversion.register
|
||||||
class Exam(ExamBase):
|
class Exam(ExamBase):
|
||||||
app_name = "rapids"
|
app_name = "rapids"
|
||||||
|
|
||||||
exam_questions = SortedManyToManyField(Rapid, related_name="exams", blank="true")
|
#exam_questions = SortedManyToManyField(Rapid, related_name="exams", blank="true")
|
||||||
|
exam_questions = models.ManyToManyField(Rapid, through=ExamQuestionDetail, related_name="exams")
|
||||||
|
|
||||||
time_limit = models.IntegerField(
|
time_limit = models.IntegerField(
|
||||||
help_text="Exam time limit (in seconds). Default is 2100 secondse (35 minutes)",
|
help_text="Exam time limit (in seconds). Default is 2100 secondse (35 minutes)",
|
||||||
|
|||||||
Reference in New Issue
Block a user