Skip to content

Commit

Permalink
fix: quiz form
Browse files Browse the repository at this point in the history
  • Loading branch information
adilmohak committed Oct 5, 2024
1 parent 103c4a7 commit 045df6b
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def check_if_correct(self, guess):

def order_choices(self, queryset):
if self.choice_order == "content":
return queryset.order_by("choice")
return queryset.order_by("choice_text")
elif self.choice_order == "random":
return queryset.order_by("?")
else:
Expand Down
11 changes: 9 additions & 2 deletions quiz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,15 @@ def dispatch(self, request, *args, **kwargs):
"You have already completed this quiz. Only one attempt is permitted.",
)
return redirect("quiz_index", slug=self.course.slug)

# Set self.question and self.progress here
self.question = self.sitting.get_first_question()
self.progress = self.sitting.progress()

return super().dispatch(request, *args, **kwargs)

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
self.question = self.sitting.get_first_question()
self.progress = self.sitting.progress()
kwargs["question"] = self.question
return kwargs

Expand Down Expand Up @@ -292,6 +295,10 @@ def form_valid_user(self, form):
self.sitting.add_user_answer(self.question, guess)
self.sitting.remove_first_question()

# Update self.question and self.progress for the next question
self.question = self.sitting.get_first_question()
self.progress = self.sitting.progress()

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["question"] = self.question
Expand Down
2 changes: 1 addition & 1 deletion static/css/style.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/css/style.min.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion static/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ a {
}

.progress-bar {
animation: loader-bar ease-in-out 7s forwards;
animation: loader-bar ease-in-out 3s forwards;
}
@keyframes loader-bar {
0%,
Expand Down Expand Up @@ -1301,3 +1301,7 @@ video {
box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.16),
0px 2px 10px 0px rgba(0, 0, 0, 0.12);
}

.breadcrumb-item a {
color: var(--bs-primary);
}
15 changes: 7 additions & 8 deletions templates/quiz/correct_answer.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
{% load i18n %}
{% if previous.answers %}

{% if user_was_incorrect %}
<div class="alert alert-error">
<strong>{% trans "You answered the above question incorrectly" %}</strong>
</div>
{% endif %}

<table class="table table-striped table-bordered">
<tbody>
{% for answer in previous.answers %}
{% if answer.correct %}
<tr class="success">
<td>{{ answer }}</td>
<td><strong>{% trans "This is the correct answer" %}</strong></td>
<td class="text-success"><strong>{% trans "This is the correct answer" %}</strong></td>
</tr>
{% else %}
<tr>
Expand All @@ -30,4 +23,10 @@
{% endfor %}
</tbody>
</table>

{% if user_was_incorrect %}
<div class="text-danger">
<strong>{% trans "You answered the above question incorrectly" %}</strong>
</div>
{% endif %}
{% endif %}
2 changes: 1 addition & 1 deletion templates/quiz/mcquestion_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{% endif %}

<div class="container">
<div class="info-text bg-orange mb-3">{{ quizQuestions }} {% trans 'question added' %}</div>
<div class="mb-3 bg-secondary text-light py-1 px-3">{{ quiz_questions_count }} {% trans 'question added' %}</div>

<form action="#" method="POST">{% csrf_token %}
{% if form.errors %}<p class="alert alert-danger">{% trans 'Correct the error(s) below.' %}</p>{% endif %}
Expand Down
18 changes: 9 additions & 9 deletions templates/quiz/question.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% else %}
<div class="alert alert-warning">
{% endif %}
<p><small>
<p class="mb-0"><small>
{% trans "Your answer was" %} </small>
<strong>
{{ previous.previous_outcome|yesno:"correct,incorrect" }}
Expand All @@ -44,20 +44,13 @@

{% load i18n %}
{% if previous.answers %}

{% if user_was_incorrect %}
<div class="alert alert-error">
<strong>{% trans "You answered the above question incorrectly" %}</strong>
</div>
{% endif %}

<table class="table table-striped table-bordered">
<tbody>
{% for answer in previous.answers %}
{% if answer.correct %}
<tr class="success">
<td>{{ answer }}</td>
<td><strong>{% trans "This is the correct answer" %}</strong></td>
<td class="text-success"><strong>{% trans "This is the correct answer" %}</strong></td>
</tr>
{% else %}
<tr>
Expand All @@ -74,6 +67,13 @@
{% endfor %}
</tbody>
</table>

{% if user_was_incorrect %}
<div class="text-danger">
<strong>{% trans "You answered the above question incorrectly" %}</strong>
</div>
{% endif %}

{% endif %}


Expand Down
Loading

0 comments on commit 045df6b

Please sign in to comment.