update code

lrs-branch
lrs 1 year ago
parent a7f7c27b28
commit e2f26fff22

@ -44,7 +44,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
# 'corsheaders',
'API',
'Student',
'teacher',
@ -60,7 +60,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
# 'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
# 'API.middle.AuthMiddleware',
]

@ -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),
]

@ -12,37 +12,37 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='student',
name='s_class_name',
name='class_name',
field=models.CharField(blank=True, max_length=50, verbose_name='班级'),
),
migrations.AlterField(
model_name='student',
name='s_grade',
name='grade',
field=models.CharField(blank=True, max_length=20, verbose_name='年级'),
),
migrations.AlterField(
model_name='student',
name='s_major',
name='major',
field=models.CharField(blank=True, max_length=50, verbose_name='专业名称'),
),
migrations.AlterField(
model_name='student',
name='s_name',
name='name',
field=models.CharField(blank=True, max_length=100, verbose_name='姓名'),
),
migrations.AlterField(
model_name='student',
name='s_password',
name='password',
field=models.CharField(blank=True, max_length=100, verbose_name='密码'),
),
migrations.AlterField(
model_name='student',
name='s_sex',
name='sex',
field=models.CharField(blank=True, max_length=4, verbose_name='性别'),
),
migrations.AlterField(
model_name='student',
name='s_username',
name='username',
field=models.CharField(blank=True, max_length=30, verbose_name='用户名称'),
),
migrations.AlterField(

@ -0,0 +1,41 @@
# Generated by Django 3.2.13 on 2023-09-08 11:57
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Student', '0002_auto_20230907_0916'),
]
operations = [
migrations.RemoveField(
model_name='student',
name='class_name',
),
migrations.RemoveField(
model_name='student',
name='grade',
),
migrations.RemoveField(
model_name='student',
name='major',
),
migrations.RemoveField(
model_name='student',
name='name',
),
migrations.RemoveField(
model_name='student',
name='password',
),
migrations.RemoveField(
model_name='student',
name='sex',
),
migrations.RemoveField(
model_name='student',
name='username',
),
]

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

@ -2,22 +2,15 @@ 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
import json
@csrf_exempt
def studnets(request):

@ -12,12 +12,12 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='course',
name='c_name',
name='name',
field=models.CharField(blank=True, max_length=255, verbose_name='课程名称'),
),
migrations.AlterField(
model_name='course',
name='c_type',
name='type',
field=models.CharField(blank=True, max_length=128, verbose_name='课程类型'),
),
]

@ -12,27 +12,27 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='teacher',
name='t_dept',
name='dept',
field=models.CharField(blank=True, max_length=128, verbose_name='教师所属院系'),
),
migrations.AlterField(
model_name='teacher',
name='t_education',
name='education',
field=models.CharField(blank=True, max_length=128, verbose_name='教师学历'),
),
migrations.AlterField(
model_name='teacher',
name='t_name',
name='name',
field=models.CharField(blank=True, max_length=255, verbose_name='教师名称'),
),
migrations.AlterField(
model_name='teacher',
name='t_sex',
name='sex',
field=models.CharField(blank=True, max_length=128, verbose_name='教师性别'),
),
migrations.AlterField(
model_name='teacher',
name='t_title',
name='title',
field=models.CharField(blank=True, max_length=128, verbose_name='教师职称'),
),
]

@ -9,21 +9,28 @@ from django.views.decorators.csrf import csrf_exempt
from io import BytesIO
from django.http.multipartparser import MultiPartParser
from django.http import QueryDict
from course.models import Course,SC
from course.models import Course, SC
from Student.models import Student
from django.db.models import Q
import json
from EduSystemServer.utils import ResponseUtil
@csrf_exempt
def teacher(request):
if request.method == "POST":
teacher_information = Teacher()
teacher_information.username = request.POST.get('username')
teacher_information.password = request.POST.get('password')
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)
response = ResponseUtil.ok(teacher_information.to_dict(), "老师信息插入成功")
return JsonResponse(response)
elif request.method == "GET":
name = request.GET.get('name')
@ -56,7 +63,8 @@ def teacher(request):
all_objects = Teacher.objects.all()
for teacher_x in all_objects:
data.append(teacher_x.to_dict())
return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
response = ResponseUtil.ok(data, "老师信息查询成功")
return JsonResponse(response)
elif request.method == "DELETE":
parser = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding)
@ -70,7 +78,7 @@ def teacher(request):
response = {"code": 200, "message": "删除成功!", "data": info}
return JsonResponse(response)
except:
response = {"code": 200, "message": "删除失败,未找到老师信息!"}
response = ResponseUtil.ok("")
return JsonResponse(response)
elif request.method == 'PUT':
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
@ -104,22 +112,81 @@ def delete(request):
def teaching_resources(request):
pass
@csrf_exempt
def student_performance_management(request):
if request.method == "POST":
def student_performance_management(request): # 学生成绩管理
if request.method == "POST": # 学生成绩录入
sid = request.POST.get('sid')
cid = request.POST.get('cid')
middle_grade = float(request.POST.get('middle_grade'))
end_grade = float(request.POST.get('end_grade'))
if middle_grade <= 100 and middle_grade >= 0:
sc = SC()
sid = Student.objects.get(sid=sid)
print(sid)
cid = Course.objects.get(cid=cid)
sc.sid = sid
sc.cid = cid
sc.middle_grade = middle_grade
sc.end_grade=end_grade
sc.save()
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
if middle_grade <= 100 and middle_grade >= 0 and end_grade <= 100 and end_grade >= 0:
query = SC.objects.filter(sid = sid, cid =cid)
if query.exists(): # 如果学生存在,则修改学生成绩
query.update(middle_grade = middle_grade, end_grade= end_grade)
else: # 如果学生成绩不存在,则插入学生成绩信息
sc = SC()
sid = Student.objects.get(sid=sid)
cid = Course.objects.get(cid=cid)
sc.sid = sid
sc.cid = cid
sc.middle_grade = middle_grade
sc.end_grade=end_grade
sc.save()
filtered = SC.objects.filter(sid = sid, cid =cid)
data = filtered.values()# 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
response = ResponseUtil.ok(data,"学生成绩录入成功")
return JsonResponse(response)
else:
return JsonResponse({'code': 200, 'msg': '成绩输入有误'}, safe=False)
response = ResponseUtil.error("成绩输入有误")
return JsonResponse(response)
elif request.method == "GET":
cid = request.GET.get('cid')
c_name = request.GET.get('c_name')
sid = request.GET.get('sid')
s_name = request.GET.get('s_name')
data = []
if c_name:
data.append(SC.objects.filter(cid__name=c_name))
elif s_name:
data.append(SC.objects.filter(sid__name=s_name))
elif sid and cid:
data.append(SC.objects.filter(sid=sid, cid=cid))
elif sid:
data.append(SC.objects.filter(sid=sid))
elif cid:
data.append(SC.objects.filter(cid=cid))
else:
data.append(SC.objects.all())
response = ResponseUtil.ok(list(data[0].values()), "成绩查询成功")
return JsonResponse(response)
elif request.method == "DELETE":
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
sid = put[0]['sid']
print(sid)
try:
info = SC.objects.filter(sid=sid)
data = info.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
print(info)
SC.objects.filter(sid=sid).delete()
response = ResponseUtil.ok(data,"删除成功!")
return JsonResponse(response)
except:
response = ResponseUtil.error("未找到学生成绩")
return JsonResponse(response)
elif request.method == 'PUT':
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
# request.PUT = put[0]
print(put)
sid = put[0]['sid']
cid = put[0]['cid']
middle_grade = put[0]['middle_grade']
end_grade = put[0]['end_grade']
SC.objects.filter(sid=sid, cid=cid).update(middle_grade=middle_grade)
SC.objects.filter(sid=sid, cid=cid).update(end_grade=end_grade)
filtered = SC.objects.filter(sid=sid, cid=cid)
data = filtered.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
response = ResponseUtil.ok(data, "学生成绩修改成功")
return JsonResponse(response)

Loading…
Cancel
Save