|
|
|
@ -1,22 +1,16 @@
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
from django.http import HttpRequest
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
<<<<<<< Updated upstream
|
|
|
|
|
from .models import Student
|
|
|
|
|
=======
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
|
|
from EduSystemServer.utils import ResponseUtil
|
|
|
|
|
from Student.models import Student
|
|
|
|
|
=======
|
|
|
|
|
from .models import Student
|
|
|
|
|
>>>>>>> 1e084d20f30e0b66d5e309a483f87ce5cfe06c39
|
|
|
|
|
>>>>>>> Stashed changes
|
|
|
|
|
from teacher.models import Teacher
|
|
|
|
|
from course.models import SC, Course
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
from django.http import QueryDict
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
from django.http.multipartparser import MultiPartParser
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@ -34,47 +28,48 @@ def studnets(request):
|
|
|
|
|
student.class_name = request_data.get("class_name")
|
|
|
|
|
student.major = request_data.get("major")
|
|
|
|
|
student.save()
|
|
|
|
|
response = ResponseUtil.ok(student.to_dict(), "更新成功!")
|
|
|
|
|
response = ResponseUtil.ok(student.to_dict(), "添加成功!")
|
|
|
|
|
return JsonResponse(response)
|
|
|
|
|
except Exception as E:
|
|
|
|
|
return JsonResponse(ResponseUtil.error(E))
|
|
|
|
|
elif request.method == "GET":
|
|
|
|
|
sid = request.GET.get('sid')
|
|
|
|
|
s_name = request.GET.get('s_name')
|
|
|
|
|
s_sex = request.GET.get('s_sex')
|
|
|
|
|
s_grade = request.GET.get('s_grade')
|
|
|
|
|
s_class_name = request.GET.get('s_class_name')
|
|
|
|
|
s_major = request.GET.get('s_major')
|
|
|
|
|
name = request.GET.get('name')
|
|
|
|
|
sex = request.GET.get('sex')
|
|
|
|
|
grade = request.GET.get('grade')
|
|
|
|
|
class_name = request.GET.get('class_name')
|
|
|
|
|
major = request.GET.get('major')
|
|
|
|
|
data = []
|
|
|
|
|
if sid:
|
|
|
|
|
filtered = Student.objects.filter(sid=sid)
|
|
|
|
|
for student in filtered:
|
|
|
|
|
data.append(student.to_dict())
|
|
|
|
|
elif s_name:
|
|
|
|
|
filtered = Student.objects.filter(s_name=s_name)
|
|
|
|
|
elif name:
|
|
|
|
|
filtered = Student.objects.filter(name=name)
|
|
|
|
|
for student in filtered:
|
|
|
|
|
data.append(student.to_dict())
|
|
|
|
|
elif s_sex:
|
|
|
|
|
filtered = Student.objects.filter(s_sex=s_sex)
|
|
|
|
|
elif sex:
|
|
|
|
|
filtered = Student.objects.filter(sex=sex)
|
|
|
|
|
for student in filtered:
|
|
|
|
|
data.append(student.to_dict())
|
|
|
|
|
elif s_grade:
|
|
|
|
|
filtered = Student.objects.filter(s_grade=s_grade)
|
|
|
|
|
elif grade:
|
|
|
|
|
filtered = Student.objects.filter(grade=grade)
|
|
|
|
|
for student in filtered:
|
|
|
|
|
data.append(student.to_dict())
|
|
|
|
|
elif s_class_name:
|
|
|
|
|
filtered = Student.objects.filter(s_class_name=s_class_name)
|
|
|
|
|
elif class_name:
|
|
|
|
|
filtered = Student.objects.filter(class_name=class_name)
|
|
|
|
|
for student in filtered:
|
|
|
|
|
data.append(student.to_dict())
|
|
|
|
|
elif s_major:
|
|
|
|
|
filtered = Student.objects.filter(s_major=s_major)
|
|
|
|
|
elif major:
|
|
|
|
|
filtered = Student.objects.filter(major=major)
|
|
|
|
|
for student in filtered:
|
|
|
|
|
data.append(student.to_dict())
|
|
|
|
|
else:
|
|
|
|
|
all_objects = Student.objects.all()
|
|
|
|
|
for studnet in all_objects:
|
|
|
|
|
data.append(studnet.to_dict())
|
|
|
|
|
return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
|
|
|
|
|
for student in all_objects:
|
|
|
|
|
data.append(student.to_dict())
|
|
|
|
|
response = ResponseUtil.ok(data, "查询成功!")
|
|
|
|
|
return JsonResponse(response)
|
|
|
|
|
elif request.method == "DELETE":
|
|
|
|
|
parser = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding)
|
|
|
|
|
post_dict = parser.parse()
|
|
|
|
@ -82,42 +77,167 @@ def studnets(request):
|
|
|
|
|
try:
|
|
|
|
|
info = Student.objects.filter(sid=sid).get().to_dict()
|
|
|
|
|
Student.objects.filter(sid=sid).delete()
|
|
|
|
|
response = {"code": 200, "message": "删除成功!", "data": info}
|
|
|
|
|
response = ResponseUtil.ok(info, "删除成功!")
|
|
|
|
|
return JsonResponse(response)
|
|
|
|
|
except:
|
|
|
|
|
response = {"code": 200, "message": "删除失败,未找到学生信息!"}
|
|
|
|
|
return JsonResponse(response)
|
|
|
|
|
return JsonResponse(ResponseUtil.error("删除失败,未找到学生信息!"))
|
|
|
|
|
elif request.method == "PUT":
|
|
|
|
|
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
|
|
|
|
|
sid = put[0]['sid']
|
|
|
|
|
s_username = put[0]['s_username']
|
|
|
|
|
s_name = put[0]['s_name']
|
|
|
|
|
s_sex = put[0]['s_sex']
|
|
|
|
|
s_grade = put[0]['s_grade']
|
|
|
|
|
s_class_name = put[0]['s_class_name']
|
|
|
|
|
s_major = put[0]['s_major']
|
|
|
|
|
username = put[0]['username']
|
|
|
|
|
name = put[0]['name']
|
|
|
|
|
sex = put[0]['sex']
|
|
|
|
|
grade = put[0]['grade']
|
|
|
|
|
class_name = put[0]['class_name']
|
|
|
|
|
major = put[0]['major']
|
|
|
|
|
if Student.objects.filter(sid=sid):
|
|
|
|
|
Student.objects.filter(sid=sid).update(username=username, name=name, sex=sex, grade=grade,
|
|
|
|
|
class_name=class_name,
|
|
|
|
|
major=major)
|
|
|
|
|
else:
|
|
|
|
|
return JsonResponse(ResponseUtil.error("没有查询到该同学!"))
|
|
|
|
|
data = Student.objects.filter(sid=sid)[0].to_dict()
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(data, "修改成功!"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 查询成绩
|
|
|
|
|
def search_grade(request): # 获取SID,返回该同学的所有成绩
|
|
|
|
|
if request.method == "GET":
|
|
|
|
|
sid = request.GET.get('sid')
|
|
|
|
|
cid = SC.objects.filter(sid_id=sid).values()
|
|
|
|
|
data_list = []
|
|
|
|
|
for i in range(len(cid)):
|
|
|
|
|
c_name = Course.objects.filter(cid=cid[i]['cid_id']).values('name')[0]['name']
|
|
|
|
|
middle_grade = cid[i]['middle_grade']
|
|
|
|
|
end_grade = cid[i]['end_grade']
|
|
|
|
|
data = {
|
|
|
|
|
'c_name': c_name,
|
|
|
|
|
'平时成绩': middle_grade,
|
|
|
|
|
'最终成绩': end_grade
|
|
|
|
|
}
|
|
|
|
|
data_list.append(data)
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(data_list, "成绩查询成功!"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 修改信息
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def change_info(request):
|
|
|
|
|
if request.method == "GET":
|
|
|
|
|
sid = request.GET.get('sid')
|
|
|
|
|
info = Student.objects.filter(sid=sid).values()
|
|
|
|
|
data = {
|
|
|
|
|
'学生编号': sid,
|
|
|
|
|
'用户账号': info[0]['username'],
|
|
|
|
|
'用户密码': info[0]['password'],
|
|
|
|
|
'姓名': info[0]['name'],
|
|
|
|
|
'性别': info[0]['sex'],
|
|
|
|
|
'年级': info[0]['grade'],
|
|
|
|
|
'班级': info[0]['class_name'],
|
|
|
|
|
'专业': info[0]['major'],
|
|
|
|
|
}
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(data, "个人信息查询成功!"))
|
|
|
|
|
elif request.method == "POST":
|
|
|
|
|
sid = request.GET.get('sid')
|
|
|
|
|
stu_info = Student.objects.get(sid=sid)
|
|
|
|
|
username = request.POST.get('username') or stu_info.username
|
|
|
|
|
password = request.POST.get('password') or stu_info.password
|
|
|
|
|
name = request.POST.get('name') or stu_info.name
|
|
|
|
|
sex = request.POST.get('sex') or stu_info.sex
|
|
|
|
|
grade = request.POST.get('grade') or stu_info.grade
|
|
|
|
|
class_name = request.POST.get('class_name') or stu_info.class_name
|
|
|
|
|
major = request.POST.get('major') or stu_info.major
|
|
|
|
|
Student.objects.filter(sid=sid).update(username=username, password=password, name=name, sex=sex, grade=grade,
|
|
|
|
|
class_name=class_name, major=major)
|
|
|
|
|
data = {
|
|
|
|
|
'学生编号': sid,
|
|
|
|
|
'用户账号': username,
|
|
|
|
|
'用户密码': password,
|
|
|
|
|
'姓名': name,
|
|
|
|
|
'性别': sex,
|
|
|
|
|
'年级': grade,
|
|
|
|
|
'班级': class_name,
|
|
|
|
|
'专业': major,
|
|
|
|
|
}
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(data, "学生信息修改成功!"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 选课
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def choose_course(request):
|
|
|
|
|
if request.method == "GET": # 将所有课程信息返回
|
|
|
|
|
course_list = []
|
|
|
|
|
course = Course.objects.all().values()
|
|
|
|
|
for i in range(len(course)):
|
|
|
|
|
teacher = Teacher.objects.filter(tid=course[i]['tid_id']).values('name')
|
|
|
|
|
data = {
|
|
|
|
|
'课程编号': course[i]['cid'],
|
|
|
|
|
'课程名称': course[i]['name'],
|
|
|
|
|
'课程类型': course[i]['type'],
|
|
|
|
|
'课程学分': course[i]['credit'],
|
|
|
|
|
'教师': teacher[0]['name'],
|
|
|
|
|
}
|
|
|
|
|
course_list.append(data)
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(course_list, "课程查询成功!"))
|
|
|
|
|
elif request.method == "POST": # 将选择的课程添加到选课表
|
|
|
|
|
sid = request.GET.get('sid')
|
|
|
|
|
cid = request.POST.get('cid_id')
|
|
|
|
|
try:
|
|
|
|
|
Student.objects.filter(sid=sid).update(s_username=s_username, s_name=s_name, s_sex=s_sex, s_grade=s_grade,
|
|
|
|
|
s_class_name=s_class_name,
|
|
|
|
|
s_major=s_major)
|
|
|
|
|
SC.objects.create(sid_id=sid, cid_id=cid)
|
|
|
|
|
course = Course.objects.filter(cid=cid).values()
|
|
|
|
|
teacher = Teacher.objects.filter(tid=course[0]['tid_id']).values('name')
|
|
|
|
|
data = {
|
|
|
|
|
'课程编号': cid,
|
|
|
|
|
'课程名称': course[0]['name'],
|
|
|
|
|
'课程类型': course[0]['type'],
|
|
|
|
|
'课程学分': course[0]['credit'],
|
|
|
|
|
'教师': teacher[0]['name'],
|
|
|
|
|
}
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(data, "选课成功!"))
|
|
|
|
|
except:
|
|
|
|
|
Student.objects.create(sid=sid, s_username=s_username, s_name=s_name, s_sex=s_sex, s_grade=s_grade,
|
|
|
|
|
s_class_name=s_class_name,
|
|
|
|
|
s_major=s_major)
|
|
|
|
|
data = Student.objects.filter(sid=sid)[0].to_dict()
|
|
|
|
|
return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
|
|
|
|
|
student_list = Student.objects.all()
|
|
|
|
|
response_json = {"code": 200, "message": "success", "data": []}
|
|
|
|
|
for student in student_list:
|
|
|
|
|
response_json["data"].append(student.to_dict())
|
|
|
|
|
return JsonResponse(response_json)
|
|
|
|
|
elif request.method == 'DELETE':
|
|
|
|
|
params = QueryDict(request.body)
|
|
|
|
|
key = next(iter(params.keys())) # 获取键名
|
|
|
|
|
value = params.get(key) # 获取值
|
|
|
|
|
xx = str(value).split('-')[0]
|
|
|
|
|
print(xx.split('\r\n'))
|
|
|
|
|
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
|
|
|
|
|
return JsonResponse(ResponseUtil.error("选课失败!"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 退课
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def delete_course(request):
|
|
|
|
|
if request.method == "GET": # 返回用户所有选择的课程
|
|
|
|
|
sid = request.GET.get('sid')
|
|
|
|
|
course_list = []
|
|
|
|
|
try:
|
|
|
|
|
cid = SC.objects.filter(sid_id=sid).values('cid_id') # 通过选课表找到学生选的所有课程
|
|
|
|
|
for i in range(len(cid)):
|
|
|
|
|
course = Course.objects.filter(cid=cid[i]['cid_id']).values() # 在课程表中找课程详细信息
|
|
|
|
|
teacher = Teacher.objects.filter(tid=course[0]['tid_id']).values('name')
|
|
|
|
|
data = {
|
|
|
|
|
'课程编号': course[0]['cid'],
|
|
|
|
|
'课程名称': course[0]['name'],
|
|
|
|
|
'课程类型': course[0]['type'],
|
|
|
|
|
'课程学分': course[0]['credit'],
|
|
|
|
|
'教师': teacher[0]['name'],
|
|
|
|
|
}
|
|
|
|
|
course_list.append(data)
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(course_list, "课程查询成功!"))
|
|
|
|
|
except:
|
|
|
|
|
return JsonResponse(ResponseUtil.error('你还没有选课!'))
|
|
|
|
|
elif request.method == "POST": # 将用户选择的课程删除
|
|
|
|
|
sid = request.GET.get('sid')
|
|
|
|
|
cid = request.POST.get('cid')
|
|
|
|
|
try:
|
|
|
|
|
course = Course.objects.filter(cid=cid).values() # 在课程表中找课程详细信息
|
|
|
|
|
teacher = Teacher.objects.filter(tid=course[0]['tid_id']).values('name')
|
|
|
|
|
data = {
|
|
|
|
|
'课程编号': course[0]['cid'],
|
|
|
|
|
'课程名称': course[0]['name'],
|
|
|
|
|
'课程类型': course[0]['type'],
|
|
|
|
|
'课程学分': course[0]['credit'],
|
|
|
|
|
'教师': teacher[0]['name'],
|
|
|
|
|
}
|
|
|
|
|
SC.objects.filter(sid_id=sid, cid_id=cid).delete()
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(data, "退课成功!"))
|
|
|
|
|
except:
|
|
|
|
|
JsonResponse(ResponseUtil.error('退课失败!'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_select_course_by_id(request):
|
|
|
|
|
pass
|
|
|
|
|