|
|
@ -13,22 +13,19 @@ def login(request):
|
|
|
|
return render(request, 'login.html', )
|
|
|
|
return render(request, 'login.html', )
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
# 获取form表单参数
|
|
|
|
|
|
|
|
role = request.POST.get('role')
|
|
|
|
role = request.POST.get('role')
|
|
|
|
username = request.POST.get('username')
|
|
|
|
username = request.POST.get('username')
|
|
|
|
pwd = request.POST.get('pwd')
|
|
|
|
pwd = request.POST.get('pwd')
|
|
|
|
# 验证身份,用户名,密码
|
|
|
|
|
|
|
|
if role == '0': # 如果身份是学生
|
|
|
|
if role == '0': # 如果身份是学生
|
|
|
|
# 从学生表中查询是否有匹配结果
|
|
|
|
|
|
|
|
result = models.StuInfo.objects.filter(username=username, password=pwd)
|
|
|
|
result = models.StuInfo.objects.filter(username=username, password=pwd)
|
|
|
|
# 如果用户存在的话
|
|
|
|
|
|
|
|
if result.exists():
|
|
|
|
if result.exists():
|
|
|
|
# 重定向到学生主页,把学生ID sid 传到前台页面
|
|
|
|
|
|
|
|
return redirect('student_index', sid=result.first().id)
|
|
|
|
return redirect('student_index', sid=result.first().id)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return HttpResponse('failed')
|
|
|
|
return HttpResponse('failed')
|
|
|
|
elif role == '1':
|
|
|
|
|
|
|
|
|
|
|
|
elif role == '1': # 如果身份是管理员
|
|
|
|
result = models.AdminInfo.objects.filter(username=username, password=pwd)
|
|
|
|
result = models.AdminInfo.objects.filter(username=username, password=pwd)
|
|
|
|
if result.exists():
|
|
|
|
if result.exists():
|
|
|
|
return redirect('/manage/homepage/')
|
|
|
|
return redirect('/manage/homepage/')
|
|
|
@ -182,7 +179,7 @@ def student_index(request, sid):
|
|
|
|
student_id = request.POST.get('sid')
|
|
|
|
student_id = request.POST.get('sid')
|
|
|
|
course_obj = models.CourseInfo.objects.get(pk=course_id)
|
|
|
|
course_obj = models.CourseInfo.objects.get(pk=course_id)
|
|
|
|
student_obj = models.StuInfo.objects.get(pk=student_id)
|
|
|
|
student_obj = models.StuInfo.objects.get(pk=student_id)
|
|
|
|
# 添加学生选课信息
|
|
|
|
# 添加选课信息
|
|
|
|
student_obj.course.add(course_obj)
|
|
|
|
student_obj.course.add(course_obj)
|
|
|
|
return HttpResponse('success')
|
|
|
|
return HttpResponse('success')
|
|
|
|
|
|
|
|
|
|
|
|