.
This commit is contained in:
+12
-1
@@ -1,6 +1,13 @@
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
from rapids import views as rapid_views
|
||||||
|
|
||||||
|
from rest_framework import routers
|
||||||
|
|
||||||
|
router = routers.DefaultRouter()
|
||||||
|
router.register(r'rapids/exams', rapid_views.ExamViewSet, basename="rapid-exams")
|
||||||
|
|
||||||
app_name = "generic"
|
app_name = "generic"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -11,7 +18,11 @@ urlpatterns = [
|
|||||||
path("examination/ajax/get_examination_id",
|
path("examination/ajax/get_examination_id",
|
||||||
views.get_examination_id,
|
views.get_examination_id,
|
||||||
name="get_examination_id"),
|
name="get_examination_id"),
|
||||||
path("exam_json_edit",
|
path("generic_exam_json_edit",
|
||||||
views.generic_exam_json_edit,
|
views.generic_exam_json_edit,
|
||||||
name="generic_exam_json_edit"),
|
name="generic_exam_json_edit"),
|
||||||
|
|
||||||
|
|
||||||
|
path('api/', include(router.urls)),
|
||||||
|
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||||
]
|
]
|
||||||
|
|||||||
+3
-1
@@ -85,7 +85,9 @@ def generic_exam_json_edit(request):
|
|||||||
question_ids = json.loads(request.POST.get("add_exam_questions"))
|
question_ids = json.loads(request.POST.get("add_exam_questions"))
|
||||||
question_objects = Question.objects.filter(pk__in=question_ids)
|
question_objects = Question.objects.filter(pk__in=question_ids)
|
||||||
|
|
||||||
exam.exam_questions.add(question_objects)
|
for i in question_ids:
|
||||||
|
exam.exam_questions.add(i)
|
||||||
|
#exam.exam_questions.add(question_objects)
|
||||||
exam.save()
|
exam.save()
|
||||||
data = {"status": "success"}
|
data = {"status": "success"}
|
||||||
return JsonResponse(data, status=200)
|
return JsonResponse(data, status=200)
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ INSTALLED_APPS = [
|
|||||||
'debug_toolbar',
|
'debug_toolbar',
|
||||||
"tagulous",
|
"tagulous",
|
||||||
"dbbackup",
|
"dbbackup",
|
||||||
|
"rest_framework",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ urlpatterns = [
|
|||||||
# Global url that registers RTS compatible exams
|
# Global url that registers RTS compatible exams
|
||||||
path("exam/json/", views.active_exams, name="active_exams"),
|
path("exam/json/", views.active_exams, name="active_exams"),
|
||||||
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')),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ class RapidCreationDefaultForm(ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class RapidForm(ModelForm):
|
class RapidForm(ModelForm):
|
||||||
|
|
||||||
|
exams = ModelMultipleChoiceField(required=False, queryset=Exam.objects.all())
|
||||||
class Media:
|
class Media:
|
||||||
# Django also includes a few javascript files necessary
|
# Django also includes a few javascript files necessary
|
||||||
# for the operation of this form element. You need to
|
# for the operation of this form element. You need to
|
||||||
@@ -106,6 +108,39 @@ class RapidForm(ModelForm):
|
|||||||
choices=Rapid.LATERALITY_CHOICES, required=True, widget=RadioSelect()
|
choices=Rapid.LATERALITY_CHOICES, required=True, widget=RadioSelect()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if kwargs.get("instance"):
|
||||||
|
# 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["exams"] = [t.pk for t in kwargs["instance"].exams.all()]
|
||||||
|
|
||||||
|
ModelForm.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
# Get the unsaved Pizza instance
|
||||||
|
instance = ModelForm.save(self, False)
|
||||||
|
|
||||||
|
# Prepare a 'save_m2m' method for the form,
|
||||||
|
old_save_m2m = self.save_m2m
|
||||||
|
|
||||||
|
def save_m2m():
|
||||||
|
old_save_m2m()
|
||||||
|
# This is where we actually link the pizza with toppings
|
||||||
|
instance.exams.clear()
|
||||||
|
for exam in self.cleaned_data["exams"]:
|
||||||
|
instance.exams.add(exam)
|
||||||
|
|
||||||
|
self.save_m2m = save_m2m
|
||||||
|
|
||||||
|
# Do we need to save all changes now?
|
||||||
|
# if commit:
|
||||||
|
instance.save()
|
||||||
|
self.save_m2m()
|
||||||
|
|
||||||
|
return instance
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Rapid
|
model = Rapid
|
||||||
# fields = ['due_back']
|
# fields = ['due_back']
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# serializers.py
|
||||||
|
from rest_framework import serializers, permissions
|
||||||
|
|
||||||
|
|
||||||
|
from .models import Exam
|
||||||
|
|
||||||
|
class ExamSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Exam
|
||||||
|
fields = ('name', 'id', 'active', "publish_results")
|
||||||
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
@@ -16,6 +16,11 @@
|
|||||||
</span>
|
</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
Exams: {% for exam in question.exams.all %}
|
||||||
|
<a href="{% url 'rapids:exam_overview' pk=exam.pk %}">{{ exam.name }}</a>,
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
<p class="pre-whitespace"><b>Feedback:</b> {{ question.feedback }}</p>
|
<p class="pre-whitespace"><b>Feedback:</b> {{ question.feedback }}</p>
|
||||||
<p><b>Author(s):</b> {% for author in question.author.all %} <a
|
<p><b>Author(s):</b> {% for author in question.author.all %} <a
|
||||||
href="{% url 'rapids:author_detail' pk=author.pk %}">{{author}}</a>, {% endfor %}</p>
|
href="{% url 'rapids:author_detail' pk=author.pk %}">{{author}}</a>, {% endfor %}</p>
|
||||||
|
|||||||
@@ -15,22 +15,54 @@
|
|||||||
</div>
|
</div>
|
||||||
{% render_table table %}
|
{% render_table table %}
|
||||||
|
|
||||||
<button id="button-select-add-exam"></button>
|
<button id="button-select-add-exam" data-exam_list_url="{% url 'generic:rapid-exams-list' %}">Add selected questions to
|
||||||
|
exam</button>
|
||||||
|
<div id="exam-options"></div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$("#button-select-add-exam").click(function () {
|
$("#button-select-add-exam").click(function (evt) {
|
||||||
// Find selected objects
|
// Find selected objects
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var jqxhr = $.get(evt.target.dataset.exam_list_url, function (data) {
|
||||||
|
console.log(data);
|
||||||
|
data.forEach((obj, n) => {
|
||||||
|
$("#exam-options").append($(document.createElement('button')).prop({
|
||||||
|
type: 'button',
|
||||||
|
innerHTML: obj.name,
|
||||||
|
class: '',
|
||||||
|
|
||||||
|
}).data("exam-id", obj.id).click((evt) => { addToExam(evt) }))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.done(function () {
|
||||||
|
//alert( "second success" );
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//alert( "error" );
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//alert( "finished" );
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
function addToExam(evt) {
|
||||||
|
|
||||||
|
ids = []
|
||||||
|
$("table input:checked").each((n, el) => {
|
||||||
|
ids.push(el.value)
|
||||||
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "{% url 'generic:generic_exam_json_edit' %}",
|
url: "{% url 'generic:generic_exam_json_edit' %}",
|
||||||
data: {
|
data: {
|
||||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
add_exam_questions: $("table input:checked").serialize(),
|
add_exam_questions: JSON.stringify(ids),
|
||||||
type: "rapid",
|
type: "rapid",
|
||||||
exam_id: exam_id,
|
exam_id: $(evt.target).data("exam-id"),
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
@@ -45,7 +77,9 @@
|
|||||||
})
|
})
|
||||||
.always(function () {
|
.always(function () {
|
||||||
console.log('[Done]');
|
console.log('[Done]');
|
||||||
|
$("#exam-options").empty();
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ from django.forms.models import model_to_dict
|
|||||||
from rapids.forms import RapidCreationDefaultForm
|
from rapids.forms import RapidCreationDefaultForm
|
||||||
from rapids.models import RapidCreationDefault
|
from rapids.models import RapidCreationDefault
|
||||||
|
|
||||||
|
|
||||||
|
from rest_framework import viewsets
|
||||||
|
|
||||||
|
from .serializers import ExamSerializer
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -876,3 +882,7 @@ class QuestionDelete(AuthorOrCheckerRequiredMixin, DeleteView):
|
|||||||
success_url = reverse_lazy("rapids:rapid_view")
|
success_url = reverse_lazy("rapids:rapid_view")
|
||||||
|
|
||||||
RapidExamViews = ExamViews(Exam, Rapid, "rapids", "rapid", loadJsonAnswer)
|
RapidExamViews = ExamViews(Exam, Rapid, "rapids", "rapid", loadJsonAnswer)
|
||||||
|
|
||||||
|
class ExamViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Exam.objects.all().order_by('name')
|
||||||
|
serializer_class = ExamSerializer
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ opencv-python
|
|||||||
pydicom
|
pydicom
|
||||||
django-dbbackup
|
django-dbbackup
|
||||||
django-hashedfilenamestorage
|
django-hashedfilenamestorage
|
||||||
|
djangorestframework
|
||||||
Reference in New Issue
Block a user