.
This commit is contained in:
+6
-13
@@ -7,7 +7,7 @@ from django.forms import (
|
||||
CharField,
|
||||
)
|
||||
from django.forms import inlineformset_factory
|
||||
from generic.forms import ExamFormMixin
|
||||
from generic.forms import ExamAuthorFormMixin, ExamFormMixin
|
||||
|
||||
from longs.models import (
|
||||
# Examination,
|
||||
@@ -267,16 +267,9 @@ LongSeriesImageFormSet = inlineformset_factory(
|
||||
|
||||
|
||||
class ExamForm(ExamFormMixin, ModelForm):
|
||||
class Meta:
|
||||
class Meta(ExamFormMixin.Meta):
|
||||
model = Exam
|
||||
fields = [
|
||||
"name",
|
||||
"time_limit",
|
||||
"open_access",
|
||||
"authors_only",
|
||||
"exam_mode",
|
||||
"active",
|
||||
"publish_results",
|
||||
"double_mark",
|
||||
"archive",
|
||||
]
|
||||
|
||||
class ExamAuthorForm(ExamAuthorFormMixin):
|
||||
class Meta(ExamAuthorFormMixin.Meta):
|
||||
model = Exam
|
||||
@@ -0,0 +1,32 @@
|
||||
# Generated by Django 3.2.13 on 2022-05-21 20:35
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('generic', '0032_userprofile_registration_number'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('longs', '0061_exam_valid_user_users'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ciduseranswer',
|
||||
name='user',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='user_longs_user_answers', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='exam',
|
||||
name='cid_user_groups',
|
||||
field=models.ManyToManyField(blank=True, help_text='These groups define which candidates are able to be added to the exams/collection.', related_name='longs_cid_user_groups', to='generic.CidUserGroup'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='exam',
|
||||
name='user_user_groups',
|
||||
field=models.ManyToManyField(blank=True, help_text='These groups define which candidates are able to be added to the exams/collection.', related_name='longs_user_user_groups', to='generic.UserUserGroup'),
|
||||
),
|
||||
]
|
||||
+24
-1
@@ -28,7 +28,7 @@ from helpers.images import image_as_base64, pretty_print_dicom
|
||||
|
||||
from anatomy.models import Modality
|
||||
|
||||
from generic.models import CidUser, Examination, Condition, Sign, ExamBase, Plane, Contrast, QuestionNote
|
||||
from generic.models import CidUser, CidUserGroup, Examination, Condition, Sign, ExamBase, Plane, Contrast, QuestionNote, UserUserGroup
|
||||
|
||||
# from generic.models import Examination, Site, Condition, Sign
|
||||
|
||||
@@ -601,6 +601,21 @@ class Exam(ExamBase):
|
||||
settings.AUTH_USER_MODEL, blank=True, related_name="user_longs_exams"
|
||||
)
|
||||
|
||||
cid_user_groups = models.ManyToManyField(
|
||||
CidUserGroup,
|
||||
blank=True,
|
||||
help_text="These groups define which candidates are able to be added to the exams/collection.",
|
||||
related_name="longs_cid_user_groups"
|
||||
|
||||
)
|
||||
|
||||
user_user_groups = models.ManyToManyField(
|
||||
UserUserGroup,
|
||||
blank=True,
|
||||
help_text="These groups define which candidates are able to be added to the exams/collection.",
|
||||
related_name="longs_user_user_groups"
|
||||
)
|
||||
|
||||
def get_exam_question_json(self, question_id):
|
||||
q = get_object_or_404(Long, pk=question_id)
|
||||
|
||||
@@ -722,6 +737,14 @@ class CidUserAnswer(models.Model):
|
||||
help_text="Candidate ID (limitied by BigIntegerField size)",
|
||||
)
|
||||
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
related_name="user_longs_user_answers",
|
||||
)
|
||||
|
||||
# Each user answer is associated with a particular exam
|
||||
exam = models.ForeignKey(
|
||||
Exam, related_name="cid_user_answers", on_delete=models.CASCADE, null=True
|
||||
|
||||
@@ -91,6 +91,7 @@ urlpatterns = [
|
||||
name="exam_question_detail",
|
||||
),
|
||||
path("exam/<int:pk>/", views.GenericExamViews.exam_overview, name="exam_overview"),
|
||||
path("exam/<int:pk>/authors", views.ExamAuthorUpdate.as_view(), name="exam_authors"),
|
||||
path(
|
||||
"exam/<int:pk>/json_edit",
|
||||
views.GenericExamViews.exam_json_edit,
|
||||
|
||||
+6
-1
@@ -25,6 +25,7 @@ from django.http import Http404, JsonResponse
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
|
||||
from .forms import (
|
||||
ExamAuthorForm,
|
||||
LongForm,
|
||||
LongSeriesForm,
|
||||
LongSeriesImageFormSet,
|
||||
@@ -74,7 +75,7 @@ from django.forms.models import model_to_dict
|
||||
from longs.forms import LongCreationDefaultForm
|
||||
from longs.models import LongCreationDefault
|
||||
|
||||
from generic.views import ExamCloneMixin, ExamViews
|
||||
from generic.views import AuthorRequiredMixin, ExamCloneMixin, ExamViews
|
||||
from reversion.views import RevisionMixin
|
||||
import reversion
|
||||
|
||||
@@ -1141,6 +1142,10 @@ class ExamUpdate(
|
||||
form.instance.author.add(self.request.user.id)
|
||||
return super().form_valid(form)
|
||||
|
||||
class ExamAuthorUpdate(RevisionMixin, LoginRequiredMixin, AuthorRequiredMixin, UpdateView):
|
||||
model = Exam
|
||||
form_class = ExamAuthorForm
|
||||
|
||||
|
||||
class ExamDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView):
|
||||
model = Exam
|
||||
|
||||
Reference in New Issue
Block a user