Add customizable passing threshold and display statistics to students
This commit is contained in:
+10
-22
@@ -125,23 +125,12 @@ class SubmissionAdmin(ModelAdmin):
|
||||
|
||||
@admin.display(description='Статистика (сохраните оценку в формате X/Y, чтобы обновить)')
|
||||
def statistics(self, obj):
|
||||
if not obj or not obj.grade:
|
||||
stats = obj.get_statistics() if obj else None
|
||||
|
||||
if not stats:
|
||||
return format_html('<div style="color: #8b949e;">Оценка не выставлена или имеет неверный формат. Укажите оценку в формате "X/Y" (например, "3/27").</div>')
|
||||
|
||||
try:
|
||||
parts = obj.grade.split('/')
|
||||
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%)"
|
||||
color = "#2ea043" if is_passed else "#f85149"
|
||||
|
||||
total_int = int(total) if total.is_integer() else total
|
||||
threshold_points = int(total * 0.4)
|
||||
|
||||
return format_html(
|
||||
'''
|
||||
<div style="background-color: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 20px; color: #c9d1d9; font-family: ui-sans-serif, system-ui, sans-serif;">
|
||||
@@ -173,17 +162,16 @@ class SubmissionAdmin(ModelAdmin):
|
||||
</div>
|
||||
''',
|
||||
grade=obj.grade,
|
||||
percentage_str=percentage_str,
|
||||
threshold_text=threshold_text,
|
||||
color=color,
|
||||
total_int=total_int,
|
||||
threshold_points=threshold_points
|
||||
percentage_str=stats['percentage_str'],
|
||||
threshold_text=stats['threshold_text'],
|
||||
color=stats['color'],
|
||||
total_int=stats['total'],
|
||||
threshold_points=stats['threshold_points']
|
||||
)
|
||||
except Exception as e:
|
||||
return format_html(
|
||||
'<div style="color: #f85149;">Оценка имеет неверный формат. Ошибка: {error}<br>Значение: "{val}"</div>',
|
||||
error=str(e),
|
||||
val=obj.grade
|
||||
'<div style="color: #f85149;">Ошибка при отрисовке статистики: {error}</div>',
|
||||
error=str(e)
|
||||
)
|
||||
|
||||
def get_queryset(self, request):
|
||||
|
||||
Reference in New Issue
Block a user