Compare commits

..

2 Commits

Author SHA1 Message Date
lrs fd5e26b71a Further improvement of teacher functions
1 year ago
lrs d2b971806f Further improvement of teacher functions
1 year ago

@ -12,5 +12,7 @@ from .views import *
urlpatterns = [ urlpatterns = [
path("", teacher), path("", teacher),
path('delete/',delete), path('delete/',delete),
path('student/',student_performance_management) path('student/',student_performance_management),
path('query/',query_student_information),
path('course/',teaching_resources)
] ]

@ -40,29 +40,20 @@ def teacher(request):
dept = request.GET.get('dept') dept = request.GET.get('dept')
data = [] data = []
if name: if name:
filtered = Teacher.objects.filter(name=name) data.append(Teacher.objects.filter(name=name))
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif sex: elif sex:
filtered = Teacher.objects.filter(sex=sex) data.append(Teacher.objects.filter(sex=sex))
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif title: elif title:
filtered = Teacher.objects.filter(title=title) data.append(Teacher.objects.filter(title=title))
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif education: elif education:
filtered = Teacher.objects.filter(education=education) data.append(Teacher.objects.filter(education=education))
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif dept: elif dept:
filtered = Teacher.objects.filter(dept=dept) data.append(Teacher.objects.filter(dept=dept))
for teacher_x in filtered:
data.append(teacher_x.to_dict())
else: else:
all_objects = Teacher.objects.all() data.append(Teacher.objects.all())
for teacher_x in all_objects: data_x = []
data.append(teacher_x.to_dict()) for teacher_x in data[0]:
data_x.append(teacher_x.to_dict())
response = ResponseUtil.ok(data, "老师信息查询成功") response = ResponseUtil.ok(data, "老师信息查询成功")
return JsonResponse(response) return JsonResponse(response)
@ -90,16 +81,11 @@ def teacher(request):
title = put[0]['title'] title = put[0]['title']
education = put[0]['education'] education = put[0]['education']
dept = put[0]['dept'] dept = put[0]['dept']
Teacher.objects.filter(tid=tid).update(name=name) Teacher.objects.filter(tid=tid).update(name=name,sex=sex,title=title)
Teacher.objects.filter(tid=tid).update(sex=sex) Teacher.objects.filter(tid=tid).update(education=education,dept=dept)
Teacher.objects.filter(tid=tid).update(title=title)
Teacher.objects.filter(tid=tid).update(education=education)
Teacher.objects.filter(tid=tid).update(dept=dept)
data = Teacher.objects.filter(tid=tid)[0].to_dict() data = Teacher.objects.filter(tid=tid)[0].to_dict()
return JsonResponse({'code': 200, 'msg': 'success','data':data}, safe=False) return JsonResponse({'code': 200, 'msg': 'success','data':data}, safe=False)
def delete(request): def delete(request):
tid = request.GET.get('tid') tid = request.GET.get('tid')
try: try:
@ -110,7 +96,77 @@ def delete(request):
@csrf_exempt @csrf_exempt
def teaching_resources(request): def teaching_resources(request):
pass if request.method == 'POST':
cid = request.POST.get('cid')
name = request.POST.get('name')
type = request.POST.get('type')
credit = request.POST.get('credit')
tid = request.POST.get('tid')
t_name = request.POST.get('t_name')
# 定义空查询条件
conditions = Q()
t_conditions = Q()
if cid:
conditions &= Q(cid=cid)
if name:
conditions &= Q(name=name)
if type:
conditions &= Q(type=type)
if credit:
conditions &= Q(credit=credit)
if tid:
t_conditions &= Q(tid=tid)
if t_name:
t_conditions &= Q(t_name=t_name)
# 添加非空查询条件至基本查询集
query1 = Course.objects.filter(conditions)
query2 = Teacher.objects.filter(t_conditions)
combined_data = []
for item in query2:
matching_items = query1.filter(tid=item.tid).values()
combined_data.extend(matching_items)
print(combined_data)
response = ResponseUtil.ok("课程信息查询成功")
return JsonResponse(response)
elif request.method == "GET":
pass
@csrf_exempt
def query_student_information(request):
if request.method == 'POST':
name = request.POST.get('name')
sid = request.POST.get('sid')
sex = request.POST.get('sex')
grade = request.POST.get('grade')
class_name = request.POST.get('class_name')
major = request.POST.get('major')
# 定义空查询条件
conditions = Q()
if name:
conditions &= Q(name=name)
if sid:
conditions &= Q(sid=sid)
if sex:
conditions &= Q(sex=sex)
if grade:
conditions &= Q(grade=grade)
if class_name:
conditions &= Q(class_name=class_name)
if major:
conditions &= Q(major=major)
# 添加非空查询条件至基本查询集
query = Student.objects.filter(conditions)
data = query.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
print(query)
response = ResponseUtil.ok(data, "学生信息查询成功")
return JsonResponse(response)
elif request.method == "GET":
query = Student.objects.all()
data = query.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
response = ResponseUtil.ok(data, "学生信息查询成功")
return JsonResponse(response)
@csrf_exempt @csrf_exempt
def student_performance_management(request): # 学生成绩管理 def student_performance_management(request): # 学生成绩管理
if request.method == "POST": # 学生成绩录入 if request.method == "POST": # 学生成绩录入

Loading…
Cancel
Save