feat: add support for TABLE_AUTO question type with table input rendering and auto-grading

This commit is contained in:
Dmitry Belan
2026-09-19 12:19:02 +03:00
parent 9ee1788692
commit 46319def76
9 changed files with 157 additions and 19 deletions
@@ -51,6 +51,32 @@
<span class="material-icons text-[14px] align-middle">help_outline</span> Ожидает проверки
{% endif %}
</p>
{% elif answer.question.question_type == 'TABLE_AUTO' %}
<p class="text-gray-800 mb-2"><strong>Ваш ответ:</strong></p>
{% load lms_tags %}
{% with table_data=answer.text_answer|parse_json %}
{% if table_data %}
<table class="w-full border-collapse border border-gray-300 mb-4 text-sm bg-white">
{% for row in table_data %}
<tr>
<td class="border border-gray-300 p-2">{{ row.0 }}</td>
<td class="border border-gray-300 p-2">{{ row.1 }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p class="text-gray-800">Нет ответа</p>
{% endif %}
{% endwith %}
<p class="text-sm mt-1 {% if answer.is_correct %}text-green-600{% elif answer.is_correct == False %}text-red-600{% else %}text-gray-500{% endif %}">
{% if answer.is_correct %}
<span class="material-icons text-[14px] align-middle">check_circle</span> Верно
{% elif answer.is_correct == False %}
<span class="material-icons text-[14px] align-middle">cancel</span> Неверно
{% else %}
<span class="material-icons text-[14px] align-middle">help_outline</span> Ожидает проверки
{% endif %}
</p>
{% else %}
{% if answer.file_answer %}
<p class="text-gray-800"><strong>Прикрепленный файл:</strong> <a href="{{ answer.file_answer.url }}" class="text-blue-600 hover:underline">Скачать</a></p>
@@ -72,7 +98,7 @@
<form method="post" enctype="multipart/form-data" class="space-y-6">
{% csrf_token %}
{% for q, field in question_fields %}
{% for q, field_type, field in question_fields %}
<div class="p-5 border rounded-xl bg-gray-50 border-gray-200">
<h4 class="font-semibold text-lg mb-2 text-gray-800">Задача {{ forloop.counter }}</h4>
<div class="prose max-w-none text-gray-700 mb-4">
@@ -88,10 +114,22 @@
{% endif %}
<div class="bg-white p-4 rounded-lg border border-gray-200">
<label for="{{ field.id_for_label }}" class="block text-sm font-medium text-gray-700 mb-2">{{ field.label }}</label>
{{ field }}
{% if field.errors %}
<p class="mt-1 text-sm text-red-600">{{ field.errors.0 }}</p>
{% if field_type == 'table' %}
<p class="block text-sm font-medium text-gray-700 mb-2">Заполните таблицу:</p>
<table class="w-full border-collapse border border-gray-300 mb-4">
{% for row_fields in field %}
<tr>
<td class="border border-gray-300 p-2">{{ row_fields.0 }}</td>
<td class="border border-gray-300 p-2">{{ row_fields.1 }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<label for="{{ field.id_for_label }}" class="block text-sm font-medium text-gray-700 mb-2">{{ field.label }}</label>
{{ field }}
{% if field.errors %}
<p class="mt-1 text-sm text-red-600">{{ field.errors.0 }}</p>
{% endif %}
{% endif %}
</div>
</div>