|
|
|
@ -1,22 +1,20 @@
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from django.core import serializers
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
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 django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
from django.http import QueryDict
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
from django.http.multipartparser import MultiPartParser
|
|
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@ -119,5 +117,69 @@ def studnets(request):
|
|
|
|
|
print(xx.split('\r\n'))
|
|
|
|
|
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def add_student(request):
|
|
|
|
|
if not request.method == "POST":
|
|
|
|
|
return JsonResponse(ResponseUtil.error("request method error!"))
|
|
|
|
|
try:
|
|
|
|
|
request_data = json.loads(request.body)
|
|
|
|
|
student = Student()
|
|
|
|
|
student.username = request_data.get("username")
|
|
|
|
|
student.password = request_data.get("password")
|
|
|
|
|
student.name = request_data.get("name")
|
|
|
|
|
student.sex = request_data.get("sex")
|
|
|
|
|
student.grade = request_data.get("grade")
|
|
|
|
|
student.class_name = request_data.get("class_name")
|
|
|
|
|
student.major = request_data.get("major")
|
|
|
|
|
student.save()
|
|
|
|
|
result = ResponseUtil.ok(student.to_dict(), "添加成功!")
|
|
|
|
|
except Exception as E:
|
|
|
|
|
result = ResponseUtil.error(E)
|
|
|
|
|
return JsonResponse(result)
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def search_student(request):
|
|
|
|
|
currentPage = request.GET.get("currentPage")
|
|
|
|
|
pageSize = request.GET.get("pageSize")
|
|
|
|
|
request_data = json.loads(request.body)
|
|
|
|
|
search_students = Student.objects.all()
|
|
|
|
|
if not request_data.get("sid") == "":
|
|
|
|
|
search_students =search_students.filter(sid=request_data.get("sid"))
|
|
|
|
|
if not request_data.get("name") == "":
|
|
|
|
|
search_students =search_students.filter(name__contains=request_data.get("name"))
|
|
|
|
|
if not request_data.get("sex") == "":
|
|
|
|
|
search_students =search_students.filter(sex=request_data.get("sex"))
|
|
|
|
|
if not request_data.get("class_name") == "":
|
|
|
|
|
search_students =search_students.filter(class_name__contains=request_data.get("class_name"))
|
|
|
|
|
if not request_data.get("major") == "":
|
|
|
|
|
search_students =search_students.filter(major__contains=request_data.get("major"))
|
|
|
|
|
paginator = Paginator(search_students, pageSize)
|
|
|
|
|
try:
|
|
|
|
|
students = paginator.page(currentPage).object_list
|
|
|
|
|
except PageNotAnInteger:
|
|
|
|
|
students = paginator.page(1)
|
|
|
|
|
except EmptyPage:
|
|
|
|
|
students = paginator.page(paginator.num_pages).object_list
|
|
|
|
|
result = ResponseUtil.ok(json.loads(serializers.serialize("json", students)), "success!")
|
|
|
|
|
result["pageTotal"] = paginator.count
|
|
|
|
|
result["pageNum"] = paginator.num_pages
|
|
|
|
|
return JsonResponse(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def del_student(request):
|
|
|
|
|
if not request.method == "GET":
|
|
|
|
|
return JsonResponse(ResponseUtil.error("request method error!"))
|
|
|
|
|
try:
|
|
|
|
|
sid = request.GET.get("sid")
|
|
|
|
|
student = Student.objects.filter(sid=sid).first()
|
|
|
|
|
student.delete()
|
|
|
|
|
result = ResponseUtil.ok(None, "删除成功!")
|
|
|
|
|
except Exception as E:
|
|
|
|
|
result = ResponseUtil.error(E)
|
|
|
|
|
return JsonResponse(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_select_course_by_id(request):
|
|
|
|
|
pass
|
|
|
|
|