Fix tuple index out of range in format_html for statistics
This commit is contained in:
+10
-5
@@ -133,6 +133,7 @@ class SubmissionAdmin(ModelAdmin):
|
||||
earned = float(parts[0].strip())
|
||||
total = float(parts[1].strip())
|
||||
percentage = (earned / total) * 100 if total > 0 else 0
|
||||
percentage_str = f"{percentage:.1f}"
|
||||
|
||||
is_passed = percentage >= 40
|
||||
threshold_text = "Выше порога" if is_passed else "Ниже порога (Мин: 40%)"
|
||||
@@ -156,11 +157,11 @@ class SubmissionAdmin(ModelAdmin):
|
||||
</div>
|
||||
<div style="flex-grow: 1; max-width: 50%; display: flex; flex-direction: column; justify-content: flex-end;">
|
||||
<div style="display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 8px;">
|
||||
<span style="color: #c9d1d9;">Выполнение: <b>{percentage:.1f}%</b></span>
|
||||
<span style="color: #c9d1d9;">Выполнение: <b>{percentage_str}%</b></span>
|
||||
<span style="color: {color}; font-weight: 500;">{threshold_text}</span>
|
||||
</div>
|
||||
<div style="width: 100%; background-color: #30363d; border-radius: 9999px; height: 6px; overflow: hidden; margin-bottom: 8px;">
|
||||
<div style="background-color: {color}; width: {percentage}%; height: 100%; border-radius: 9999px;"></div>
|
||||
<div style="background-color: {color}; width: {percentage_str}%; height: 100%; border-radius: 9999px;"></div>
|
||||
</div>
|
||||
<div style="display: flex; justify-content: space-between; font-size: 11px; color: #8b949e; font-family: ui-monospace, SFMono-Regular, monospace;">
|
||||
<span>0 б</span>
|
||||
@@ -172,14 +173,18 @@ class SubmissionAdmin(ModelAdmin):
|
||||
</div>
|
||||
''',
|
||||
grade=obj.grade,
|
||||
percentage=percentage,
|
||||
percentage_str=percentage_str,
|
||||
threshold_text=threshold_text,
|
||||
color=color,
|
||||
total_int=total_int,
|
||||
threshold_points=threshold_points
|
||||
)
|
||||
except Exception:
|
||||
return format_html('<div style="color: #f85149;">Оценка имеет неверный формат. Используйте формат "X/Y" (например, "3/27").</div>')
|
||||
except Exception as e:
|
||||
return format_html(
|
||||
'<div style="color: #f85149;">Оценка имеет неверный формат. Ошибка: {error}<br>Значение: "{val}"</div>',
|
||||
error=str(e),
|
||||
val=obj.grade
|
||||
)
|
||||
|
||||
def get_queryset(self, request):
|
||||
qs = super().get_queryset(request)
|
||||
|
||||
Reference in New Issue
Block a user