Get test result, but it doesn't work
This commit is contained in:
parent
3135f3e3ec
commit
9b1143aa41
@ -261,4 +261,16 @@ background-color:#FF0B7E
|
||||
|
||||
.returnLink{
|
||||
color: #00916E;
|
||||
}
|
||||
|
||||
.testContent input[type=submit]{
|
||||
height: 30px;
|
||||
color: #FFF;
|
||||
font-size: 15px;
|
||||
background: #00916E;
|
||||
cursor: pointer;
|
||||
border-radius: 25px;
|
||||
border: none;
|
||||
outline: none;
|
||||
margin-top: 15px;
|
||||
}
|
@ -23,27 +23,28 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<div class="card-body test_body">
|
||||
<div class="card-header test_title">
|
||||
{{ test.name }}
|
||||
</div>
|
||||
{% for question in test.questions.all %}
|
||||
<div class="card-body test_body">
|
||||
<div class="card-header test_title">
|
||||
{{ test.name }}
|
||||
</div>
|
||||
{% for question in test.questions.all %}
|
||||
|
||||
<div class="question_title">
|
||||
{{ question.description }}
|
||||
</div>
|
||||
<div class="question_title">
|
||||
{{ question.description }}
|
||||
</div>
|
||||
|
||||
<div class="list-group">
|
||||
{% for answer in question.answers.all %}
|
||||
<label class="list-group-item">
|
||||
<input class="form-check-input me-1" type="radio" name={{ question.id }} value="">
|
||||
{{ answer.description }}
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="list-group">
|
||||
{% for answer in question.answers.all %}
|
||||
<label class="list-group-item">
|
||||
<input class="form-check-input me-1" type="radio" name={{ question.id }} value={{ answer.id }}>
|
||||
{{ answer.description }}
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<input class="testContent" type="submit" value="Send answers">
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<img class="resultImage" src="http://kmit.in/emagazine/wp-content/uploads/2018/02/karnataka-results.jpg" alt="Card image cap">
|
||||
<div class="resultBody">
|
||||
<h5 class="resultMsg">Quite good! All the best for next quiz!</h5>
|
||||
<h5 class="resultScore">Score: 3</h5>
|
||||
<h5 class="resultScore">Score: {{ request.session.points }}</h5>
|
||||
|
||||
<p class="resultText">Percentage: 60%</p>
|
||||
<p class="resultText">Correct answers: 3</p>
|
||||
|
@ -6,6 +6,7 @@ from rest_framework.response import Response
|
||||
from trials.models import Test
|
||||
from trials.serializers import TestSerializer
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
|
||||
class TestModelViewSet(viewsets.ModelViewSet):
|
||||
@ -16,15 +17,33 @@ class TestTemplateView(TemplateView):
|
||||
|
||||
permission_classes = []
|
||||
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
|
||||
test_id = None
|
||||
|
||||
def get_queryset(self):
|
||||
return Test.objects.all()
|
||||
|
||||
def get_context_data(self, test_id, **kwargs):
|
||||
self.test_id = test_id
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["test"] = self.get_queryset().filter(id=test_id).prefetch_related("questions__answers").first()
|
||||
return context
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
question_id = 1
|
||||
answers = []
|
||||
while True:
|
||||
if request.POST.get(str(question_id)) is None:
|
||||
break
|
||||
ans_id = request.POST.get(str(question_id))
|
||||
answers.append({'question': question_id, 'answer': ans_id})
|
||||
question_id += 1
|
||||
points = self.get_queryset().filter(id=self.test_id).get_score(answers)
|
||||
#return redirect('account')
|
||||
request.session['points'] = points
|
||||
url = '/tests/' + str(self.test_id) + '/result'
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
|
||||
def testView(request):
|
||||
permission_classes = []
|
||||
|
Loading…
Reference in New Issue
Block a user