Fix: quiz form error
This commit is contained in:
parent
7c7376c7ab
commit
103c4a7e4e
@ -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)
|
||||
@ -134,10 +134,20 @@ class MCQuestionCreate(CreateView):
|
||||
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",
|
||||
|
||||
@ -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 %}
|
||||
|
||||
@ -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>
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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 %}
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -108,7 +108,7 @@
|
||||
</li>
|
||||
{% endif %}
|
||||
<br />
|
||||
<p class="ml-3">→ Others</p>
|
||||
<p class="ms-3 text-secondary">→ 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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user