|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
|
|
|
|
|
from django.db.models import F, Subquery, Max
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
|
|
|
|
|
from EduSystemServer.utils import ResponseUtil
|
|
|
|
|
from EduSystemServer.utils import *
|
|
|
|
|
from course.models import *
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
from io import BytesIO
|
|
|
|
@ -73,6 +74,9 @@ def courses(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def search_course(request):
|
|
|
|
|
"""
|
|
|
|
|
通过条件查询课程,并且分页显示
|
|
|
|
|
"""
|
|
|
|
|
if not request.method == "GET":
|
|
|
|
|
return JsonResponse(ResponseUtil.error("request method error!"))
|
|
|
|
|
teacher_name = request.GET.get("tName")
|
|
|
|
@ -105,6 +109,9 @@ def search_course(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_course_by_student_id(request):
|
|
|
|
|
"""
|
|
|
|
|
通过学生ID获取学生的选课
|
|
|
|
|
"""
|
|
|
|
|
if not request.method == "GET":
|
|
|
|
|
return JsonResponse(ResponseUtil.error("request method error!"))
|
|
|
|
|
s_username = request.jwt_payload.get("username")
|
|
|
|
@ -119,6 +126,9 @@ def get_course_by_student_id(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_select_course(request):
|
|
|
|
|
"""
|
|
|
|
|
删除选课
|
|
|
|
|
"""
|
|
|
|
|
if not request.method == "GET":
|
|
|
|
|
return JsonResponse(ResponseUtil.error("request method error!"))
|
|
|
|
|
try:
|
|
|
|
@ -130,4 +140,68 @@ def delete_select_course(request):
|
|
|
|
|
except Exception as E:
|
|
|
|
|
return JsonResponse(ResponseUtil.error(E))
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
@teacher_required
|
|
|
|
|
@admin_required
|
|
|
|
|
def get_student_select_course(request):
|
|
|
|
|
"""
|
|
|
|
|
获取所有学生的所有选课
|
|
|
|
|
"""
|
|
|
|
|
if not request.method == "POST":
|
|
|
|
|
return JsonResponse(ResponseUtil.error("request method error!"))
|
|
|
|
|
current_page = request.GET.get("currentPage")
|
|
|
|
|
sname = request.POST.get("sname")
|
|
|
|
|
className = request.POST.get("className")
|
|
|
|
|
courseName = request.POST.get("courseName")
|
|
|
|
|
courseType = request.POST.get("courseType")
|
|
|
|
|
sc_list = SC.objects.all().filter(
|
|
|
|
|
sid__name__contains=sname,
|
|
|
|
|
sid__class_name__contains=className,
|
|
|
|
|
cid__name__contains=courseName,
|
|
|
|
|
cid__type__contains=courseType
|
|
|
|
|
).annotate(
|
|
|
|
|
sname=F("sid__name"),
|
|
|
|
|
className=F("sid__class_name"),
|
|
|
|
|
cname=F("cid__name"), ctype=F("cid__type"),
|
|
|
|
|
endGrade=F("end_grade"),
|
|
|
|
|
middleGrade=F("middle_grade")
|
|
|
|
|
).values(
|
|
|
|
|
"sname", "className", "cname",
|
|
|
|
|
"ctype", "endGrade", "middleGrade",
|
|
|
|
|
"sid", "cid"
|
|
|
|
|
).distinct()
|
|
|
|
|
paginator = Paginator(sc_list, 10)
|
|
|
|
|
try:
|
|
|
|
|
sc_list = paginator.page(current_page).object_list
|
|
|
|
|
except PageNotAnInteger:
|
|
|
|
|
sc_list = paginator.page(1)
|
|
|
|
|
except EmptyPage:
|
|
|
|
|
sc_list = paginator.page(paginator.num_pages).object_list
|
|
|
|
|
data = []
|
|
|
|
|
for student in sc_list:
|
|
|
|
|
data.append(student)
|
|
|
|
|
result = ResponseUtil.ok(data, "success!")
|
|
|
|
|
result["pageTotal"] = paginator.count
|
|
|
|
|
result["pageNum"] = paginator.num_pages
|
|
|
|
|
return JsonResponse(result)
|
|
|
|
|
|
|
|
|
|
@teacher_required
|
|
|
|
|
@admin_required
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def edit_grade(request):
|
|
|
|
|
"""
|
|
|
|
|
成绩录入
|
|
|
|
|
"""
|
|
|
|
|
if not request.method == "POST":
|
|
|
|
|
return JsonResponse(ResponseUtil.error("request method error!"))
|
|
|
|
|
try:
|
|
|
|
|
sid = request.POST.get("sid")
|
|
|
|
|
cid = request.POST.get("cid")
|
|
|
|
|
sc = SC.objects.filter(sid=sid, cid=cid).first()
|
|
|
|
|
sc.middle_grade = request.POST.get("middleGrade")
|
|
|
|
|
sc.end_grade = request.POST.get("endGrade")
|
|
|
|
|
sc.save()
|
|
|
|
|
return JsonResponse(ResponseUtil.ok(None, "成绩修改成功!"))
|
|
|
|
|
except Exception as E:
|
|
|
|
|
return JsonResponse(ResponseUtil.error(str(E)))
|
|
|
|
|
|
|
|
|
|