Get test result, but it doesn't work
This commit is contained in:
parent
3135f3e3ec
commit
9b1143aa41
@ -262,3 +262,15 @@ background-color:#FF0B7E
|
|||||||
.returnLink{
|
.returnLink{
|
||||||
color: #00916E;
|
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 %}
|
{% block content %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body test_body">
|
<div class="card-body test_body">
|
||||||
<div class="card-header test_title">
|
<div class="card-header test_title">
|
||||||
{{ test.name }}
|
{{ test.name }}
|
||||||
</div>
|
</div>
|
||||||
{% for question in test.questions.all %}
|
{% for question in test.questions.all %}
|
||||||
|
|
||||||
<div class="question_title">
|
<div class="question_title">
|
||||||
{{ question.description }}
|
{{ question.description }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
{% for answer in question.answers.all %}
|
{% for answer in question.answers.all %}
|
||||||
<label class="list-group-item">
|
<label class="list-group-item">
|
||||||
<input class="form-check-input me-1" type="radio" name={{ question.id }} value="">
|
<input class="form-check-input me-1" type="radio" name={{ question.id }} value={{ answer.id }}>
|
||||||
{{ answer.description }}
|
{{ answer.description }}
|
||||||
</label>
|
</label>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
<input class="testContent" type="submit" value="Send answers">
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% 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">
|
<img class="resultImage" src="http://kmit.in/emagazine/wp-content/uploads/2018/02/karnataka-results.jpg" alt="Card image cap">
|
||||||
<div class="resultBody">
|
<div class="resultBody">
|
||||||
<h5 class="resultMsg">Quite good! All the best for next quiz!</h5>
|
<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">Percentage: 60%</p>
|
||||||
<p class="resultText">Correct answers: 3</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.models import Test
|
||||||
from trials.serializers import TestSerializer
|
from trials.serializers import TestSerializer
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
|
|
||||||
|
|
||||||
class TestModelViewSet(viewsets.ModelViewSet):
|
class TestModelViewSet(viewsets.ModelViewSet):
|
||||||
@ -16,15 +17,33 @@ class TestTemplateView(TemplateView):
|
|||||||
|
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
|
template_name = settings.BASE_DIR + f"/templates/generic_test.html"
|
||||||
|
test_id = None
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Test.objects.all()
|
return Test.objects.all()
|
||||||
|
|
||||||
def get_context_data(self, test_id, **kwargs):
|
def get_context_data(self, test_id, **kwargs):
|
||||||
|
self.test_id = test_id
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["test"] = self.get_queryset().filter(id=test_id).prefetch_related("questions__answers").first()
|
context["test"] = self.get_queryset().filter(id=test_id).prefetch_related("questions__answers").first()
|
||||||
return context
|
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):
|
def testView(request):
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
|
Loading…
Reference in New Issue
Block a user