.
This commit is contained in:
@@ -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:
|
||||||
@@ -25,3 +30,26 @@ 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
@@ -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)),
|
||||||
|
|||||||
@@ -161,3 +161,9 @@ 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
|
||||||
Reference in New Issue
Block a user