Задача {{ forloop.counter }}
@@ -88,10 +114,22 @@
{% endif %}
-
- {{ field }}
- {% if field.errors %}
-
{{ field.errors.0 }}
+ {% if field_type == 'table' %}
+
Заполните таблицу:
+
+ {% for row_fields in field %}
+
+ | {{ row_fields.0 }} |
+ {{ row_fields.1 }} |
+
+ {% endfor %}
+
+ {% else %}
+
+ {{ field }}
+ {% if field.errors %}
+
{{ field.errors.0 }}
+ {% endif %}
{% endif %}
diff --git a/lmsege/lms/templatetags/lms_tags.py b/lmsege/lms/templatetags/lms_tags.py
index c8c023d..ff485b1 100644
--- a/lmsege/lms/templatetags/lms_tags.py
+++ b/lmsege/lms/templatetags/lms_tags.py
@@ -5,3 +5,12 @@ register = template.Library()
@register.simple_tag
def get_submission(submissions_dict, assignment_id):
return submissions_dict.get(assignment_id)
+
+import json
+
+@register.filter
+def parse_json(value):
+ try:
+ return json.loads(value)
+ except (ValueError, TypeError):
+ return None
diff --git a/lmsege/lms/views.py b/lmsege/lms/views.py
index 90562ae..1e32a9d 100644
--- a/lmsege/lms/views.py
+++ b/lmsege/lms/views.py
@@ -2,6 +2,7 @@ from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.html import strip_tags
from .models import Assignment, Submission, Answer
+import json
from .forms import AnswersForm, StudentRegistrationForm
from django.contrib.auth import login
def register(request):
@@ -84,6 +85,35 @@ def assignment_detail(request, pk):
else:
all_auto = False
max_points += 1
+ elif q.question_type == 'TABLE_AUTO':
+ rows = getattr(q, 'table_rows', 2) or 2
+ table_data = []
+ for i in range(1, rows + 1):
+ val1 = form.cleaned_data.get(f'answer_{q.id}_r{i}_c1', '')
+ val2 = form.cleaned_data.get(f'answer_{q.id}_r{i}_c2', '')
+ table_data.append([val1, val2])
+ answer_obj.text_answer = json.dumps(table_data)
+ if q.correct_answer:
+ correct_rows = q.correct_answer.split(';')
+ is_correct = True
+ if len(correct_rows) != rows:
+ is_correct = False
+ else:
+ for i, row in enumerate(correct_rows):
+ cols = row.split('|')
+ if len(cols) == 2:
+ if cols[0].strip().lower() != table_data[i][0].strip().lower() or cols[1].strip().lower() != table_data[i][1].strip().lower():
+ is_correct = False
+ break
+ else:
+ is_correct = False
+ break
+ answer_obj.is_correct = is_correct
+ answer_obj.points = 1 if is_correct else 0
+ total_points += answer_obj.points
+ else:
+ all_auto = False
+ max_points += 1
else:
all_auto = False
val = form.cleaned_data.get(f'file_{q.id}')
@@ -104,8 +134,16 @@ def assignment_detail(request, pk):
question_fields = []
if form:
for q in questions:
- field = form[f'answer_{q.id}'] if q.question_type == 'TEXT_AUTO' else form[f'file_{q.id}']
- question_fields.append((q, field))
+ if q.question_type == 'TEXT_AUTO':
+ question_fields.append((q, 'text', form[f'answer_{q.id}']))
+ elif q.question_type == 'TABLE_AUTO':
+ rows = getattr(q, 'table_rows', 2) or 2
+ table_fields = []
+ for i in range(1, rows + 1):
+ table_fields.append([form[f'answer_{q.id}_r{i}_c1'], form[f'answer_{q.id}_r{i}_c2']])
+ question_fields.append((q, 'table', table_fields))
+ else:
+ question_fields.append((q, 'file', form[f'file_{q.id}']))
return render(request, 'lms/assignment_detail.html', {
'assignment': assignment,
diff --git a/lmsege/lmsege/__pycache__/settings.cpython-314.pyc b/lmsege/lmsege/__pycache__/settings.cpython-314.pyc
index 8973d36..958a2c3 100644
Binary files a/lmsege/lmsege/__pycache__/settings.cpython-314.pyc and b/lmsege/lmsege/__pycache__/settings.cpython-314.pyc differ