update code

master
bettleChen 1 year ago
parent a7f7c27b28
commit afade783a0

@ -22,7 +22,6 @@ def login(request):
request.session["username"] = student.username
request.session["type"] = "student"
result = ResponseUtil.ok(student.to_dict(), "login success!")
result = {"code": 0, "message": "login success!"}
else:
result = {"code": -1, "message": "username or password error!"}
elif _type == "teacher":
@ -32,7 +31,6 @@ def login(request):
request.session["username"] = teacher.username
request.session["type"] = "teacher"
result = ResponseUtil.ok(teacher.to_dict(), "login success!")
result = {"code": 0, "message": "login success!"}
else:
result = ResponseUtil.error("username or password error!")
else:

@ -16,26 +16,15 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
from API.views import login, get_user_info
<<<<<<< Updated upstream
=======
>>>>>>> Stashed changes
urlpatterns = [
path('Eduadmin/', admin.site.urls),
path('api/', include(("API.urls", "api"), namespace="api")),
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
>>>>>>> Stashed changes
path('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")),
path('student/', include(("Student.urls", "student"), namespace="student")),
path('course/', include(("course.urls", "course"), namespace="course")),
=======
path('student/', include(("Student.urls", "studnet"), namespace="student")),
>>>>>>> Stashed changes
path('login', login),
path('userinfo', get_user_info),
]

@ -4,38 +4,6 @@ from django.db import models
# Create your models here.
class Student(models.Model):
sid = models.AutoField(primary_key=True, verbose_name="学生编号", name="sid")
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
>>>>>>> Stashed changes
<<<<<<< HEAD
s_username = models.CharField(max_length=30, verbose_name="用户名称", name="s_username", blank=True)
s_password = models.CharField(max_length=100, verbose_name="密码", name="s_password", blank=True)
s_name = models.CharField(max_length=100, verbose_name="姓名", name="s_name", blank=True)
s_sex = models.CharField(max_length=4, verbose_name="性别", name="s_sex", blank=True)
s_grade = models.CharField(max_length=20, verbose_name="年级", name="s_grade", blank=True)
s_class_name = models.CharField(max_length=50, verbose_name="班级", name="s_class_name", blank=True)
s_major = models.CharField(max_length=50, verbose_name="专业名称", name="s_major", blank=True)
def to_dict(self):
return {"sid": self.sid, "s_name": self.s_name, "s_username": self.s_username, "s_password": self.s_password,
"s_sex": self.s_sex, "s_grade": self.s_grade, "class_name": self.s_class_name, "s_major": self.s_major}
=======
username = models.CharField(max_length=30, verbose_name="用户名称", name="username", blank=True)
password = models.CharField(max_length=100, verbose_name="密码", name="password", blank=True)
name = models.CharField(max_length=100, verbose_name="姓名", name="name", blank=True)
sex = models.CharField(max_length=4, verbose_name="性别", name="sex", blank=True)
grade = models.CharField(max_length=20, verbose_name="年级", name="grade", blank=True)
class_name = models.CharField(max_length=50, verbose_name="班级", name="class_name", blank=True)
major = models.CharField(max_length=50, verbose_name="专业名称", name="major", blank=True)
def to_dict(self):
return {"sid": self.sid, "name": self.name, "username": self.username, "password": self.password,
"sex": self.sex, "grade": self.grade, "class_name": self.class_name, "major": self.major}
>>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa
<<<<<<< Updated upstream
=======
=======
username = models.CharField(max_length=30, verbose_name="用户名称", name="username", blank=True)
password = models.CharField(max_length=100, verbose_name="密码", name="password", blank=True)
name = models.CharField(max_length=100, verbose_name="姓名", name="name", blank=True)
@ -47,8 +15,6 @@ class Student(models.Model):
def to_dict(self):
return {"sid": self.sid, "name": self.name, "username": self.username, "password": self.password,
"sex": self.sex, "grade": self.grade, "class_name": self.class_name, "major": self.major}
>>>>>>> Stashed changes
>>>>>>> Stashed changes
class Meta:
db_table = "student"

@ -4,5 +4,8 @@ from .views import *
urlpatterns = [
path("", studnets),
path("selectCourse", get_select_course_by_id)
path("search", search_student),
path("selectCourse", get_select_course_by_id),
path("add", add_student),
path("delete", del_student)
]

@ -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

@ -4,6 +4,8 @@ from django.shortcuts import render
# Create your views here.
from django.http import JsonResponse
from EduSystemServer.utils import ResponseUtil
from .models import Teacher
from django.views.decorators.csrf import csrf_exempt
from io import BytesIO
@ -12,18 +14,24 @@ from django.http import QueryDict
from course.models import Course,SC
from Student.models import Student
import json
@csrf_exempt
def teacher(request):
if request.method == "POST":
teacher_information = Teacher()
teacher_information.name = request.POST.get('name')
teacher_information.sex = request.POST.get('sex')
teacher_information.title = request.POST.get('title')
teacher_information.education = request.POST.get('education')
teacher_information.dept = request.POST.get('dept')
teacher_information.save()
print(teacher_information.name)
return JsonResponse({'code': 200, 'msg': 'success',"data": teacher_information.to_dict()}, safe=False)
try:
request_data = json.loads(request.body)
teacher_information = Teacher.objects.filter(tid=request_data.get("tid")).first()
teacher_information.name = request_data.get('name')
teacher_information.sex = request_data.get('sex')
teacher_information.title = request_data.get('title')
teacher_information.education = request_data.get('education')
teacher_information.dept = request_data.get('dept')
teacher_information.username = request_data.get("username")
teacher_information.password = request_data.get("password")
teacher_information.save()
return JsonResponse(ResponseUtil.ok(teacher_information.to_dict(), "更新成功"))
except Exception as E:
return JsonResponse(ResponseUtil.error(E))
elif request.method == "GET":
name = request.GET.get('name')

Loading…
Cancel
Save