This commit is contained in:
Ross
2021-05-04 23:27:35 +01:00
parent 59ae57d7f0
commit a7826c003b
3 changed files with 38 additions and 4 deletions
+29 -1
View File
@@ -15,6 +15,11 @@ from generic.models import (
from django.contrib.admin.widgets import FilteredSelectMultiple from django.contrib.admin.widgets import FilteredSelectMultiple
from django.forms.widgets import RadioSelect, TextInput, Textarea from django.forms.widgets import RadioSelect, TextInput, Textarea
from rapids.models import Rapid
from anatomy.models import AnatomyQuestion
from longs.models import Long
from django.shortcuts import render, get_object_or_404, redirect
class ExaminationForm(ModelForm): class ExaminationForm(ModelForm):
class Meta: class Meta:
@@ -24,4 +29,27 @@ class ExaminationForm(ModelForm):
class QuestionNoteForm(ModelForm): class QuestionNoteForm(ModelForm):
class Meta: class Meta:
model = QuestionNote model = QuestionNote
fields = ["content_type", "object_id", "author", "note_type", "note"] fields = ["content_type", "object_id", "author", "note_type", "note"]
def __init__(self, *args, **kwargs):
question_type = kwargs.pop("question_type")
if question_type == "rapid":
question = Rapid
elif question_type == "anatomy":
question = AnatomyQuestion
elif question_type == "long":
question = AnatomyQuestion
else:
raise PermissionError()
get_object_or_404(question, pk=kwargs.pop("pk"))
# We get the 'initial' keyword argument or initialize it
# as a dict if it didn't exist.
initial = kwargs.setdefault("initial", {})
# The widget for a ModelMultipleChoiceField expects
# a list of primary key for the selected data.
#initial["content_type"] = [t.pk for t in kwargs["instance"].exams.all()]
ModelForm.__init__(self, *args, **kwargs)
#super(QuestionNoteForm(), self).__init__(*args, **kwargs)
+2 -2
View File
@@ -55,8 +55,8 @@ urlpatterns = [
path("exam/json/unbased", views.active_exams_unbased, name="active_exams_unbased"), path("exam/json/unbased", views.active_exams_unbased, name="active_exams_unbased"),
path("exam/submit", views.exam_submit, name="global_exam_answers_submit"), path("exam/submit", views.exam_submit, name="global_exam_answers_submit"),
#path('', include('generic.urls')), #path('', include('generic.urls')),
path("feedback/<str:question_type>/<int:pk>", views.feedback_create, name="feedback_create"), path("feedback/<str:question_type>/<int:pk>", views.AddQuestionNote.as_view(), name="feedback_create"),
path("feedback/", views.AddQuestionNote.as_view(), name="feedback"), #path("feedback/", views.AddQuestionNote.as_view(), name="feedback"),
path('api/', include(router.urls)), path('api/', include(router.urls)),
+7 -1
View File
@@ -160,4 +160,10 @@ def feedback_create(request, question_type, pk):
class AddQuestionNote(LoginRequiredMixin, CreateView): class AddQuestionNote(LoginRequiredMixin, CreateView):
model = QuestionNote model = QuestionNote
form_class = QuestionNoteForm form_class = QuestionNoteForm
def get_form_kwargs(self):
kwargs = super(AddQuestionNote, self).get_form_kwargs()
# update the kwargs for the form init method with yours
kwargs.update(self.kwargs) # self.kwargs contains all url conf params
return kwargs