.
This commit is contained in:
Executable
+31
@@ -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"]
|
||||
@@ -4,6 +4,11 @@
|
||||
CID: {{cid}}
|
||||
|
||||
<h2>Question [{{pos}}/{{exam_length}}]</h2>
|
||||
|
||||
<div><p>{{question.stem}}</p></div>
|
||||
|
||||
{{form}}
|
||||
<ul></ul>
|
||||
|
||||
<div>
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user