first commit

main
Lyanling 2 months ago
parent 89801f2e62
commit 5933adeb5b

@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2024-10-07 16:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('polls', '0002_student'),
]
operations = [
migrations.AddField(
model_name='student',
name='called_count',
field=models.IntegerField(default=0),
),
]

@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2024-10-07 16:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('polls', '0003_student_called_count'),
]
operations = [
migrations.AddField(
model_name='student',
name='protected',
field=models.BooleanField(default=False),
),
]

@ -17,6 +17,8 @@ class Student(models.Model):
student_id = models.CharField(max_length=100, unique=True) # 学号设为唯一 student_id = models.CharField(max_length=100, unique=True) # 学号设为唯一
score = models.FloatField(default=0) # 积分允许为小数 score = models.FloatField(default=0) # 积分允许为小数
attendance_count = models.IntegerField(default=0) # 到课次数 attendance_count = models.IntegerField(default=0) # 到课次数
called_count = models.IntegerField(default=0) # 被点名次数
protected = models.BooleanField(default=False) # 是否有保护权
def __str__(self): def __str__(self):
return self.name return self.name

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>积分排行榜</title>
</head>
<body>
<h1>积分排行榜</h1>
<table border="1">
<tr>
<th>排名</th>
<th>学号</th>
<th>姓名</th>
<th>积分</th>
<th>到课次数</th>
</tr>
{% for student in students %}
<tr>
<td>{{ forloop.counter }}</td> <!-- 使用forloop.counter显示排名 -->
<td>{{ student.student_id }}</td>
<td>{{ student.name }}</td>
<td>{{ student.score }}</td>
<td>{{ student.attendance_count }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>

@ -8,4 +8,5 @@ urlpatterns = [
path('upload/', views.upload_students, name='upload_students'), path('upload/', views.upload_students, name='upload_students'),
path('roll_call/', views.roll_call, name='roll_call'), path('roll_call/', views.roll_call, name='roll_call'),
path('confirm_roll_call/', views.confirm_roll_call, name='confirm_roll_call'), # 确认点名 path('confirm_roll_call/', views.confirm_roll_call, name='confirm_roll_call'), # 确认点名
path('leaderboard/', views.leaderboard, name='leaderboard'),
] ]

@ -4,6 +4,8 @@ from .models import *
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
import random import random
import pandas as pd import pandas as pd
from django.db.models import Window, F
from django.db.models.functions import Rank
# 导入表单 # 导入表单
from .forms import UploadFileForm from .forms import UploadFileForm
# Create your views here. # Create your views here.
@ -101,3 +103,8 @@ def confirm_roll_call(request):
return redirect('roll_call') # 返回点名页面,进行下一轮点名 return redirect('roll_call') # 返回点名页面,进行下一轮点名
return render(request, 'confirm_roll_call.html', {'student': student}) # 渲染确认点名页面 return render(request, 'confirm_roll_call.html', {'student': student}) # 渲染确认点名页面
# 积分排行榜
def leaderboard(request):
students = Student.objects.all().order_by('-score') # 按分数降序排列
return render(request, 'leaderboard.html', {'students': students})
Loading…
Cancel
Save