Skip to content

Commit 19e2950

Browse files
committed
added student quiz result
1 parent cac6306 commit 19e2950

File tree

9 files changed

+84
-13
lines changed

9 files changed

+84
-13
lines changed

django_school/classroom/templates/classroom/students/quiz_list.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
<thead>
88
<tr>
99
<th>Quiz</th>
10-
<th>Subject</th>
11-
<th>Length</th>
10+
<th class="d-none d-sm-table-cell">Subject</th>
11+
<th class="d-none d-sm-table-cell">Length</th>
1212
<th></th>
1313
</tr>
1414
</thead>
1515
<tbody>
1616
{% for quiz in quizzes %}
1717
<tr>
1818
<td class="align-middle">{{ quiz.name }}</td>
19-
<td class="align-middle">{{ quiz.subject.get_html_badge }}</td>
20-
<td class="align-middle">{{ quiz.questions_count }} questions</td>
19+
<td class="align-middle d-none d-sm-table-cell">{{ quiz.subject.get_html_badge }}</td>
20+
<td class="align-middle d-none d-sm-table-cell">{{ quiz.questions_count }} questions</td>
2121
<td class="text-right">
2222
<a href="{% url 'students:take_quiz' quiz.pk %}" class="btn btn-primary">Start quiz</a>
2323
</td>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% extends 'base.html' %}
2+
{% load quiz_extras %}
3+
4+
{% block content %}
5+
{% include 'classroom/students/_header.html' %}
6+
7+
<h2>{{quiz.name}}</h2>
8+
{{ quiz.subject.get_html_badge }}
9+
{% for question in questions %}
10+
<div class="card">
11+
<div class="card-body">
12+
<h5 class="card-title">{{forloop.counter}}. {{question.text}}</h5>
13+
<table class="table table-bordered table-sm">
14+
<thead><tr><th>Yours</th><th>Correct</th><th></th></tr></thead>
15+
<tbody>
16+
{% for opt in question.answers.all %}
17+
{% marked_answer user opt as opt_marked %}
18+
<tr>
19+
<td style="width: 100px;{% if opt_marked == 'correct' %} background:green{% elif opt_marked == 'wrong' %} background:red{% endif %}"> </td>
20+
<td style="width: 100px;{% if opt.is_correct %} background:green{% endif %}"></td>
21+
<td>{{opt.text}}</td>
22+
</tr>
23+
{% endfor %}
24+
</tbody>
25+
</table>
26+
</div>
27+
</div>
28+
<br>
29+
{% endfor %}
30+
{% endblock %}

django_school/classroom/templates/classroom/students/taken_quiz_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<tbody>
1515
{% for taken_quiz in taken_quizzes %}
1616
<tr>
17-
<td>{{ taken_quiz.quiz.name }}</td>
17+
<td><a href="{% url 'students:student_quiz_results' taken_quiz.quiz.id %}">{{ taken_quiz.quiz.name }}</a></td>
1818
<td>{{ taken_quiz.quiz.subject.get_html_badge }}</td>
1919
<td>{{ taken_quiz.score }}</td>
2020
</tr>

django_school/classroom/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django import template
2+
from classroom.models import StudentAnswer
3+
register = template.Library()
4+
5+
6+
7+
@register.simple_tag
8+
def marked_answer(user,opt):
9+
studentanswer = StudentAnswer.objects.filter(student=user.student, answer =opt)
10+
if studentanswer:
11+
if opt.is_correct:
12+
return 'correct'
13+
return 'wrong'
14+
15+
return ''

django_school/classroom/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
path('', students.QuizListView.as_view(), name='quiz_list'),
1010
path('interests/', students.StudentInterestsView.as_view(), name='student_interests'),
1111
path('taken/', students.TakenQuizListView.as_view(), name='taken_quiz_list'),
12-
path('quiz/<int:pk>/', students.take_quiz, name='take_quiz'),
12+
path('quiz/<int:pk>/', students.take_quiz, name='take_quiz'),
13+
path('quiz/<int:pk>/studentresults/', students.QuizResultsView.as_view(), name='student_quiz_results'),
1314
], 'classroom'), namespace='students')),
1415

1516
path('teachers/', include(([

django_school/classroom/views/students.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
from django.urls import reverse_lazy
88
from django.utils.decorators import method_decorator
99
from django.views.generic import CreateView, ListView, UpdateView
10+
from django.views import View
1011

1112
from ..decorators import student_required
1213
from ..forms import StudentInterestsForm, StudentSignUpForm, TakeQuizForm
13-
from ..models import Quiz, Student, TakenQuiz, User
14+
from ..models import Quiz, Student, TakenQuiz, User, Question
1415

1516

1617
class StudentSignUpView(CreateView):
@@ -61,6 +62,23 @@ def get_queryset(self):
6162
return queryset
6263

6364

65+
@method_decorator([login_required, student_required], name='dispatch')
66+
class QuizResultsView(View):
67+
template_name = 'classroom/students/quiz_result.html'
68+
69+
def get(self, request, *args, **kwargs):
70+
quiz = Quiz.objects.get(id = kwargs['pk'])
71+
if not TakenQuiz.objects.filter(student = request.user.student, quiz = quiz):
72+
"""
73+
Don't show the result if the user didn't attempted the quiz
74+
"""
75+
return render(request, '404.html')
76+
questions = Question.objects.filter(quiz =quiz)
77+
78+
# questions = self.form_class(initial=self.initial)
79+
return render(request, self.template_name, {'questions':questions, 'quiz':quiz})
80+
81+
6482
@method_decorator([login_required, student_required], name='dispatch')
6583
class TakenQuizListView(ListView):
6684
model = TakenQuiz

django_school/static/css/bootstrap.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

django_school/templates/base.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
66
<title>{% block title %}Django School{% endblock %}</title>
77
<link rel="icon" href="{% static 'img/favicon.png' %}">
8-
<link href="https://fonts.googleapis.com/css?family=Clicker+Script" rel="stylesheet">
9-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
8+
<!-- <link href="https://fonts.googleapis.com/css?family=Clicker+Script" rel="stylesheet"> -->
9+
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
1010
<link rel="stylesheet" type="text/css" href="{% static 'vendor/fontello-2f186091/css/fontello.css' %}">
1111
<link rel="stylesheet" type="text/css" href="{% static 'css/app.css' %}">
1212
{% if user.is_authenticated and user.is_teacher %}
@@ -16,7 +16,7 @@
1616
{% endif %}
1717
</head>
1818
<body>
19-
<a href="https://github.com/sibtc/django-multiple-user-types-example"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
19+
<!-- <a href="https://github.com/sibtc/django-multiple-user-types-example"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a> -->
2020
<div class="container my-4">
2121
<div class="row justify-content-center">
2222
<div class="col-md-10 col-sm-12">
@@ -68,13 +68,13 @@ <h1 class="logo">
6868
</div>
6969
</div>
7070
</div>
71-
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
72-
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
71+
<!-- <script src="{% static 'js/jquery-3.3.1.min.js' %}"></script> -->
72+
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
7373
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
7474
<script type="text/javascript">
7575
$(function () {
7676
$('[data-toggle="tooltip"]').tooltip();
7777
})
78-
</script>
78+
</script> -->
7979
</body>
8080
</html>

0 commit comments

Comments
 (0)