diff --git a/pythonProject03/.idea/vcs.xml b/pythonProject03/.idea/vcs.xml index 07e3a0f..6c0b863 100644 --- a/pythonProject03/.idea/vcs.xml +++ b/pythonProject03/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/pythonProject03/mysite10_7/polls/models.py b/pythonProject03/mysite10_7/polls/models.py index c5011aa..8c31dc0 100644 --- a/pythonProject03/mysite10_7/polls/models.py +++ b/pythonProject03/mysite10_7/polls/models.py @@ -18,7 +18,7 @@ class Student(models.Model): score = models.FloatField(default=0) # 积分允许为小数 attendance_count = models.IntegerField(default=0) # 到课次数 called_count = models.IntegerField(default=0) # 被点名次数 - protected = models.BooleanField(default=False) # 是否有保护权 + # protected = models.BooleanField(default=False) # 是否有保护权 def __str__(self): return self.name diff --git a/pythonProject03/mysite10_7/polls/templates/confirm_roll_call.html b/pythonProject03/mysite10_7/polls/templates/confirm_roll_call.html index b7c7ce3..95eb141 100644 --- a/pythonProject03/mysite10_7/polls/templates/confirm_roll_call.html +++ b/pythonProject03/mysite10_7/polls/templates/confirm_roll_call.html @@ -1,3 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -31,5 +66,10 @@ +{% if protection_awarded %} +

该学生获得保护权,自动加2分!

+{% endif %} + - \ No newline at end of file + + diff --git a/pythonProject03/mysite10_7/polls/templates/roll_call.html b/pythonProject03/mysite10_7/polls/templates/roll_call.html index fbd1afb..1229abc 100644 --- a/pythonProject03/mysite10_7/polls/templates/roll_call.html +++ b/pythonProject03/mysite10_7/polls/templates/roll_call.html @@ -1,3 +1,22 @@ + + + + + + + + + + + + + + + + + + + @@ -14,6 +33,14 @@

被选中的学生:

姓名: {{ selected_student.name }}

学号: {{ selected_student.student_id }}

+

当前积分: {{ selected_student.score }}

+

被点名次数: {{ selected_student.called_count }}

+ + + {% if protection_awarded %} +

该学生已被点名 {{ selected_student.called_count }} 次,获得保护权!下次自动加2分。

+ {% endif %} {% endif %} - \ No newline at end of file + + diff --git a/pythonProject03/mysite10_7/polls/views.py b/pythonProject03/mysite10_7/polls/views.py index c040159..9abdab3 100644 --- a/pythonProject03/mysite10_7/polls/views.py +++ b/pythonProject03/mysite10_7/polls/views.py @@ -76,33 +76,74 @@ def roll_call(request): return render(request, 'roll_call.html', {'selected_student': selected_student}) # 渲染点名页面 # 确认点名的视图 +# def confirm_roll_call(request): +# # 从 session 中获取被点名的学生 +# student_id = request.session.get('selected_student_id') +# student = get_object_or_404(Student, student_id=student_id) +# +# if request.method == 'POST': +# # 学生是否到课 +# if 'attended' in request.POST: # 如果选择了到课 +# student.score += 1 # 到课加1分 +# student.attendance_count += 1 # 到课次数加1 +# +# # 处理是否准确重复问题 +# if request.POST['question_repeat'] == 'accurate': +# student.score += 0.5 # 重复问题准确,加0.5分 +# else: +# student.score -= 1 # 重复问题不准确,扣1分 +# +# # 处理回答问题的准确性(0-3分) +# answer_accuracy = float(request.POST.get('answer_accuracy', 0)) +# student.score += answer_accuracy # 根据回答准确性加分 +# else: +# student.score -= 5 # 未到课扣5分 +# +# student.save() # 保存更新后的学生信息 +# return redirect('roll_call') # 返回点名页面,进行下一轮点名 +# +# return render(request, 'confirm_roll_call.html', {'student': student}) # 渲染确认点名页面 def confirm_roll_call(request): - # 从 session 中获取被点名的学生 student_id = request.session.get('selected_student_id') student = get_object_or_404(Student, student_id=student_id) + protection_awarded = False # 初始化保护权标志 if request.method == 'POST': - # 学生是否到课 - if 'attended' in request.POST: # 如果选择了到课 - student.score += 1 # 到课加1分 - student.attendance_count += 1 # 到课次数加1 - - # 处理是否准确重复问题 - if request.POST['question_repeat'] == 'accurate': - student.score += 0.5 # 重复问题准确,加0.5分 - else: - student.score -= 1 # 重复问题不准确,扣1分 - - # 处理回答问题的准确性(0-3分) - answer_accuracy = float(request.POST.get('answer_accuracy', 0)) - student.score += answer_accuracy # 根据回答准确性加分 + # 增加学生的被点名次数 + student.called_count += 1 + + # 检查学生是否有“保护权” + if student.called_count % 3 == 0: + # 如果被点名次数是3的倍数,赋予保护权,自动加2分 + student.score += 2 + protection_awarded = True # 设置保护权标志 + print(f"Student {student.name} ({student.student_id})获得保护权,自动加2分") else: - student.score -= 5 # 未到课扣5分 + # 学生是否到课 + if 'attended' in request.POST: # 如果选择了到课 + student.score += 1 # 到课加1分 + student.attendance_count += 1 # 到课次数加1 + + # 处理是否准确重复问题 + if request.POST['question_repeat'] == 'accurate': + student.score += 0.5 # 重复问题准确,加0.5分 + else: + student.score -= 1 # 重复问题不准确,扣1分 + + # 处理回答问题的准确性(0-3分) + answer_accuracy = float(request.POST.get('answer_accuracy', 0)) + student.score += answer_accuracy # 根据回答准确性加分 + else: + student.score -= 5 # 未到课扣5分 - student.save() # 保存更新后的学生信息 + # 保存更新后的学生信息 + student.save() return redirect('roll_call') # 返回点名页面,进行下一轮点名 - return render(request, 'confirm_roll_call.html', {'student': student}) # 渲染确认点名页面 + return render(request, 'confirm_roll_call.html', {'student': student, 'protection_awarded': protection_awarded}) # 渲染确认点名页面 + + + # 积分排行榜 def leaderboard(request):