Skip to content

Commit

Permalink
Fix: quiz form error
Browse files Browse the repository at this point in the history
  • Loading branch information
adilmohak committed Oct 5, 2024
1 parent 7c7376c commit 103c4a7
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 18 deletions.
22 changes: 16 additions & 6 deletions quiz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class MCQuestionCreate(CreateView):
form_class = MCQuestionForm
template_name = "quiz/mcquestion_form.html"

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["quiz"] = get_object_or_404(Quiz, id=self.kwargs["quiz_id"])
return kwargs
# def get_form_kwargs(self):
# kwargs = super().get_form_kwargs()
# kwargs["quiz"] = get_object_or_404(Quiz, id=self.kwargs["quiz_id"])
# return kwargs

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand All @@ -134,10 +134,20 @@ def form_valid(self, form):
formset = context["formset"]
if formset.is_valid():
with transaction.atomic():
form.instance.quiz = get_object_or_404(Quiz, id=self.kwargs["quiz_id"])
self.object = form.save()
# Save the MCQuestion instance without committing to the database yet
self.object = form.save(commit=False)
self.object.save()

# Retrieve the Quiz instance
quiz = get_object_or_404(Quiz, id=self.kwargs["quiz_id"])

# set the many-to-many relationship
self.object.quiz.add(quiz)

# Save the formset (choices for the question)
formset.instance = self.object
formset.save()

if "another" in self.request.POST:
return redirect(
"mc_create",
Expand Down
4 changes: 2 additions & 2 deletions templates/core/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url 'edit_post' pk=item.id %}"><i
class="fas fa-pencil-alt"></i>{% trans 'Edit' %}</a>
class="unstyled me-2 fas fa-pencil-alt"></i>{% trans 'Edit' %}</a>
<a class="dropdown-item" href="{% url 'delete_post' pk=item.id %}"><i
class="fas fa-trash-alt"></i>{% trans 'Delete' %}</a>
class="unstyled me-2 fas fa-trash-alt"></i>{% trans 'Delete' %}</a>
</div>
</div>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/course/course_single.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<span class="text-danger">
{% trans 'No video Uploaded.' %}
{% if request.user.is_superuser or request.user.is_lecturer %}
<a href="{% url 'upload_video' course.slug %}">
<a href="{% url 'upload_video' course.slug %}" class="text-primary">
<i class="primary" style="font-size: 22px;">
{% trans 'Upload now.' %}
</i>
Expand Down Expand Up @@ -184,7 +184,7 @@
<span class="text-danger">
{% trans 'No File Uploaded.' %}
{% if request.user.is_superuser or request.user.is_lecturer %}
<a href="{% url 'upload_file_view' course.slug %}">
<a href="{% url 'upload_file_view' course.slug %}" class="text-primary">
<i class="primary" style="font-size: 22px;">
{% trans 'Upload now.' %}
</i>
Expand Down
2 changes: 1 addition & 1 deletion templates/course/program_single.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<span class="text-danger">
{% trans 'No course for this progrm.' %}
{% if request.user.is_superuser %}
<a href="{% url 'course_add' pk=program.pk %}">
<a href="{% url 'course_add' pk=program.pk %}" class="text-primary">
<i class="primary" style="font-size: 22px;">
{% trans 'Add one now.' %}
</i>
Expand Down
2 changes: 1 addition & 1 deletion templates/quiz/mcquestion_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div class="input-group-prepend">
<span class="input-group-text">{{ fs.correct }} <small class="ms-1">{% trans 'Correct' %}</small></span>
</div>
{{ fs.choice }}
{{ fs.choice_text }}
<div class="input-group-prepend">
<span class="input-group-text">{{ fs.DELETE }} <small class="ms-1">{% trans 'Delete' %}</small></span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/quiz/progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</div>
{% endif %}
{% if not cat_scores and not exams %}
<div class="col-12 p-4 text-center"><h3><i class="far fa-frown"></i></h3> {% trans 'No recordes yet. Try to do some quizzes in your course.' %}</div>
<div class="col-12 p-4 text-center"><h3><i class="far fa-frown text-secondary"></i></h3> {% trans 'No recordes yet' %}</div>
{% endif %}

{% endblock %}
2 changes: 1 addition & 1 deletion templates/quiz/quiz_marking_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ol>
</nav>

<div class="row col-12 justify-content-between">{{ sitting.quiz }}
<div class="row col-12 justify-content-between">
<div class="header-title-md">{% trans "Quiz title" %}: {{ sitting.quiz.title }}</div>
<em class="info-text title-danger">{% trans "Category" %}: {{ sitting.quiz.category }}</em>
</div>
Expand Down
6 changes: 3 additions & 3 deletions templates/setting/admin_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
<div class="row">
<div class="col-md-6">
<div class="border-bottom">
{% trans 'Manage' %}<a class="link" href="{% url 'lecturer_list' %}">{% trans 'Lecturers' %} &raquo;</a>
{% trans 'Manage' %}<a class="link" href="{% url 'lecturer_list' %}"> {% trans 'Lecturers' %} &raquo;</a>
<p class="text-muted">CRUD (Create, Retrieve, Update &amp; Delete) lecturers</p>
</div>

<div class="border-bottom mt-3">
{% trans 'Manage' %}<a class="link" href="{% url 'student_list' %}">{% trans 'Students' %} &raquo;</a>
{% trans 'Manage' %}<a class="link" href="{% url 'student_list' %}"> {% trans 'Students' %} &raquo;</a>
<p class="text-muted">CRUD (Create, Retrieve, Update &amp; Delete) {% trans 'students' %}</p>
</div>

<div class="border-bottom mt-3">
{% trans 'Manage' %}<a class="link" href="{% url 'session_list' %}">{% trans 'Session' %} &raquo;</a>
{% trans 'Manage' %}<a class="link" href="{% url 'session_list' %}"> {% trans 'Session' %} &raquo;</a>
<p class="text-muted">CRUD (Create, Retrieve, Update &amp; Delete) {% trans 'sessions' %}</p>
</div>

Expand Down
2 changes: 1 addition & 1 deletion templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
</li>
{% endif %}
<br />
<p class="ml-3">&RightArrow; Others</p>
<p class="ms-3 text-secondary">&RightArrow; Others</p>
<li class="{% if request.path == ep %}active{% endif %}">
<a href="{% url 'edit_profile' %}"><i class="fas fa-cogs"></i>{% trans 'Account Setting' %}</a>
</li>
Expand Down

0 comments on commit 103c4a7

Please sign in to comment.