Further improvement of teacher functions

-Query student information
lrs-branch
lrs 1 year ago
parent 7bc09e1bc6
commit f0f04b1320

@ -15,5 +15,6 @@ urlpatterns = [
path('student/',student_performance_management), path('student/',student_performance_management),
path('query/',query_student_information), path('query/',query_student_information),
path('course/',teaching_resources), path('course/',teaching_resources),
path('selection/',course_selection) path('selection/',course_selection),
path('management/',student_management)
] ]

@ -98,7 +98,7 @@ def delete(request):
return JsonResponse({'code': 200, 'msg': '删除失败'}, safe=False) return JsonResponse({'code': 200, 'msg': '删除失败'}, safe=False)
@csrf_exempt @csrf_exempt
def teaching_resources(request): # 课程程序 def teaching_resources(request): # 课程查询
if request.method == 'POST': if request.method == 'POST':
cid = int(request.POST.get('cid')) cid = int(request.POST.get('cid'))
name = request.POST.get('name') name = request.POST.get('name')
@ -255,13 +255,12 @@ def student_performance_management(request): # 学生成绩管理
elif request.method == "DELETE": elif request.method == "DELETE":
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse() put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
sid = put[0]['sid'] sid = put[0]['sid']
print(sid) cid = put[0]['cid']
print(sid,cid)
try: try:
info = SC.objects.filter(sid=sid) SC.objects.filter(sid=sid, cid=cid).update(middle_grade=0,end_grade=0)
data = info.values() # 将 QuerySet 对象转换为字典列表 data = SC.objects.filter(sid=sid).values()# 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON data = list(data) # 转换为列表以便序列化为 JSON
print(info)
SC.objects.filter(sid=sid).delete()
response = ResponseUtil.ok(data,"删除成功!") response = ResponseUtil.ok(data,"删除成功!")
return JsonResponse(response) return JsonResponse(response)
except: except:
@ -283,8 +282,9 @@ def student_performance_management(request): # 学生成绩管理
response = ResponseUtil.ok(data, "学生成绩修改成功") response = ResponseUtil.ok(data, "学生成绩修改成功")
return JsonResponse(response) return JsonResponse(response)
@csrf_exempt @csrf_exempt
def course_selection(request): def course_selection(request): # 选课管理
if request.method == 'POST': if request.method == 'POST':
# 假设需要将 tid 为 1 的老师赋值给某个课程的 tid 字段 # 假设需要将 tid 为 1 的老师赋值给某个课程的 tid 字段
teacher_id = int(request.POST.get('tid')) teacher_id = int(request.POST.get('tid'))
@ -360,3 +360,129 @@ def course_selection(request):
else: else:
response = ResponseUtil.error("课程信息修改失败,信息不全") response = ResponseUtil.error("课程信息修改失败,信息不全")
return JsonResponse(response) return JsonResponse(response)
@csrf_exempt
def student_management(request):
if request.method == 'GET':
tid = request.GET.get('tid')
# 获取第1个查询表的数据
table1_result = Course.objects.filter(tid__tid=tid)
cids = [item.cid for item in table1_result]
# 获取第二个查询表的数据
table2_result = SC.objects.filter(cid__in=cids)
# for item in table2_result:
# print(item.sid.sid)
# 获取第三个查询表的数据
# 提取查询结果中的 sid 值
sids = [item.sid.sid for item in table2_result]
table3_result = Student.objects.filter(sid__in=sids).values('sid', 'name', 'sex', 'grade', 'class_name', 'major')
table = list(table3_result)
response = ResponseUtil.ok(table,"选课学生信息")
return JsonResponse(response)
if request.method == 'POST':
cid = request.POST.get('cid')
tid = request.POST.get('tid')
grade = request.POST.get('grade')
class_name = request.POST.get('class_name')
major = request.POST.get('major')
# 定义空查询条件
data = []
if cid:
data.append(SC.objects.filter(cid=cid))
else:
# 获取第1个查询表的数据
table1_result = Course.objects.filter(tid__tid=tid)
cids = [item.cid for item in table1_result]
# 获取第二个查询表的数据
data.append(SC.objects.filter(cid__in=cids))
# for item in table2_result:
# print(item.sid.sid)
# 获取第三个查询表的数据
# 提取查询结果中的 sid 值
print(data)
sids = [item.sid.sid for item in data[0]]
conditions = Q(sid__in=sids)
if grade:
conditions &= Q(grade=grade)
if class_name:
class_name &= Q(class_name=class_name)
if major:
conditions &= Q(major=major)
table3_result = Student.objects.filter(conditions).values('sid', 'name', 'sex', 'grade', 'class_name',
'major')
table = list(table3_result)
response = ResponseUtil.ok(table, "选课学生查询成功")
return JsonResponse(response)
if request.method == 'DELETE':
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
sid = put[0]['sid']
cid = put[0]['cid']
print(sid)
try:
info = SC.objects.filter(sid=sid)
data = info.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
print(info)
SC.objects.filter(sid=sid,cid=cid).delete()
response = ResponseUtil.ok(data, "学生选课删除成功!")
return JsonResponse(response)
except:
response = ResponseUtil.error("未找到学生成绩")
return JsonResponse(response)
@csrf_exempt
def SC_selection(request):
if request.method == 'GET':
cid = request.GET.get('cid')
table2_result = SC.objects.filter(cid__in=cid)
# for item in table2_result:
# print(item.sid.sid)
# 获取第三个查询表的数据
# 提取查询结果中的 sid 值
sids = [item.sid.sid for item in table2_result]
table3_result = Student.objects.filter(sid__in=sids).values('sid', 'name', 'sex', 'grade', 'class_name',
'major')
table = list(table3_result)
response = ResponseUtil.ok(table, "选课学生信息")
return JsonResponse(response)
if request.method == 'POST':
cid = request.POST.get('cid')
grade = request.POST.get('grade')
class_name = request.POST.get('class_name')
major = request.POST.get('major')
# 定义空查询条件
data = []
data.append(SC.objects.filter(cid=cid))
# 获取第三个查询表的数据
# 提取查询结果中的 sid 值
print(data)
sids = [item.sid.sid for item in data[0]]
conditions = Q(sid__in=sids)
if grade:
conditions &= Q(grade=grade)
if class_name:
class_name &= Q(class_name=class_name)
if major:
conditions &= Q(major=major)
table3_result = Student.objects.filter(conditions).values('sid', 'name', 'sex', 'grade', 'class_name',
'major')
table = list(table3_result)
response = ResponseUtil.ok(table, "选课学生查询成功")
return JsonResponse(response)
if request.method == 'DELETE':
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
sid = put[0]['sid']
cid = put[0]['cid']
print(sid)
try:
info = SC.objects.filter(sid=sid)
data = info.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
print(info)
SC.objects.filter(sid=sid, cid=cid).delete()
response = ResponseUtil.ok(data, "学生选课删除成功!")
return JsonResponse(response)
except:
response = ResponseUtil.error("未找到学生成绩")
return JsonResponse(response)
Loading…
Cancel
Save