From 4ceae2124c5f2c727f4dd182892ede6b768eb3ec Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 29 Jul 2021 18:09:29 +0100 Subject: [PATCH] . --- sbas/forms.py | 31 ++++++++++++++++++++++++++++++ sbas/templates/sbas/exam_take.html | 5 +++++ sbas/views.py | 9 +++++++++ 3 files changed, 45 insertions(+) create mode 100755 sbas/forms.py diff --git a/sbas/forms.py b/sbas/forms.py new file mode 100755 index 00000000..cbccd41a --- /dev/null +++ b/sbas/forms.py @@ -0,0 +1,31 @@ +from django.forms import ( + Form, + ModelForm, + ModelMultipleChoiceField, + ModelChoiceField, + ChoiceField, + CharField, +) +from django.forms import inlineformset_factory + +from rapids.models import ( + Question, + CidUserAnswer, + Exam, +) + +from django.contrib.admin.widgets import FilteredSelectMultiple +from django.forms.widgets import RadioSelect, TextInput, Textarea + + +class CidUserAnswerForm(ModelForm): + class Meta: + model = CidUserAnswer + fields = ["answer"] + + +# This should be made generic? +class ExamForm(ModelForm): + class Meta: + model = Exam + fields = ["name", "time_limit", "exam_mode", "active"] \ No newline at end of file diff --git a/sbas/templates/sbas/exam_take.html b/sbas/templates/sbas/exam_take.html index 61de3e44..cd390131 100755 --- a/sbas/templates/sbas/exam_take.html +++ b/sbas/templates/sbas/exam_take.html @@ -4,6 +4,11 @@ CID: {{cid}}

Question [{{pos}}/{{exam_length}}]

+ +

{{question.stem}}

+ +{{form}} +
diff --git a/sbas/views.py b/sbas/views.py index e57a33dc..fc8814ba 100644 --- a/sbas/views.py +++ b/sbas/views.py @@ -1,3 +1,4 @@ +from sbas.forms import CidUserAnswerForm from django.shortcuts import render, get_object_or_404, redirect from django.views.decorators.csrf import csrf_exempt from django import forms @@ -251,6 +252,13 @@ def exam_take(request, pk, sk, cid): pos = exam.get_question_index(question) + 1 + form = CidUserAnswerForm(request.POST or None) + if form.is_valid(): + if "next" in request.POST: + return redirect("sbas:exam_take", pk=pk, sk=n + 1, cid=cid) + elif "previous" in request.POST: + return redirect("sbas:exam_take", pk=pk, sk=n - 1, cid=cid) + previous = -1 if sk > 0: previous = sk - 1 @@ -263,6 +271,7 @@ def exam_take(request, pk, sk, cid): request, "sbas/exam_take.html", { + "form": form, "cid": cid, "exam": exam, "questions": question,