commit teacher

scl-branch
lrs 1 year ago
parent 2bb816a4ef
commit 005661deef

@ -14,7 +14,7 @@
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.8 (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (2)" project-jdk-type="Python SDK" />
</project>

@ -24,6 +24,8 @@ class SC(models.Model):
middle_grade = models.IntegerField(name="middle_grade")
end_grade = models.IntegerField(name="end_grade")
def to_dict(self):
return {"sid": self.sid, 'cid': self.cid, "middle_grade": self.middle_grade, "end_grade": self.end_grade}
class Meta:
db_table = "sc"
verbose_name = "管理员"

@ -4,15 +4,15 @@ from django.db import models
# Create your models here.
class Teacher(models.Model):
tid = models.AutoField(primary_key=True, verbose_name="教师编号", name="tid")
t_name = models.CharField(max_length=255, verbose_name="教师名称", name="t_name", blank=True)
t_sex = models.CharField(max_length=128, verbose_name="教师性别", name="t_sex", blank=True)
t_title = models.CharField(max_length=128, verbose_name="教师职称", name="t_title", blank=True)
t_education = models.CharField(max_length=128, verbose_name="教师学历", name="t_education", blank=True)
t_dept = models.CharField(max_length=128, verbose_name="教师所属院系", name="t_dept", blank=True)
name = models.CharField(max_length=255, verbose_name="教师名称", name="name", blank=True)
sex = models.CharField(max_length=128, verbose_name="教师性别", name="sex", blank=True)
title = models.CharField(max_length=128, verbose_name="教师职称", name="title", blank=True)
education = models.CharField(max_length=128, verbose_name="教师学历", name="education", blank=True)
dept = models.CharField(max_length=128, verbose_name="教师所属院系", name="dept", blank=True)
def to_dict(self):
return {"tid": self.tid, "t_name": self.t_name, "t_sex": self.t_sex, "t_title": self.t_title,
"t_education": self.t_education, "t_dept": self.t_dept}
return {"tid": self.tid, "name": self.name, "sex": self.sex, "title": self.title,
"education": self.education, "dept": self.dept}
class Meta:
db_table = "teacher"
verbose_name = "教师"

@ -11,5 +11,6 @@ from .views import *
urlpatterns = [
path("", teacher),
path('delete/',delete)
path('delete/',delete),
path('student/',student_performance_management)
]

@ -9,45 +9,47 @@ 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 Student.models import Student
import json
@csrf_exempt
def teacher(request):
if request.method == "POST":
teacher_information = Teacher()
teacher_information.t_name = request.POST.get('t_name')
teacher_information.t_sex = request.POST.get('t_sex')
teacher_information.t_title = request.POST.get('t_title')
teacher_information.t_education = request.POST.get('t_education')
teacher_information.t_dept = request.POST.get('t_dept')
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.t_name)
print(teacher_information.name)
return JsonResponse({'code': 200, 'msg': 'success',"data": teacher_information.to_dict()}, safe=False)
elif request.method == "GET":
t_name = request.GET.get('t_name')
t_sex = request.GET.get('t_sex')
t_title = request.GET.get('t_title')
t_education = request.GET.get('t_education')
t_dept = request.GET.get('t_dept')
name = request.GET.get('name')
sex = request.GET.get('sex')
title = request.GET.get('title')
education = request.GET.get('education')
dept = request.GET.get('dept')
data = []
if t_name:
filtered = Teacher.objects.filter(t_name=t_name)
if name:
filtered = Teacher.objects.filter(name=name)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif t_sex:
filtered = Teacher.objects.filter(t_sex=t_sex)
elif sex:
filtered = Teacher.objects.filter(sex=sex)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif t_title:
filtered = Teacher.objects.filter(t_title=t_title)
elif title:
filtered = Teacher.objects.filter(title=title)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif t_education:
filtered = Teacher.objects.filter(t_education=t_education)
elif education:
filtered = Teacher.objects.filter(education=education)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif t_dept:
filtered = Teacher.objects.filter(t_dept=t_dept)
elif dept:
filtered = Teacher.objects.filter(dept=dept)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
else:
@ -58,9 +60,9 @@ def teacher(request):
elif request.method == "DELETE":
parser = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding)
post_dict = parser.parse()
print(post_dict)
tid = int(post_dict[0]['tid'])
posdict = parser.parse()
print(posdict)
tid = int(posdict[0]['tid'])
print(tid)
try:
info = Teacher.objects.filter(tid=tid).get().to_dict()
@ -75,16 +77,16 @@ def teacher(request):
# request.PUT = put[0]
print(put)
tid = put[0]['tid']
t_name = put[0]['t_name']
t_sex = put[0]['t_sex']
t_title = put[0]['t_title']
t_education = put[0]['t_education']
t_dept = put[0]['t_dept']
Teacher.objects.filter(tid=tid).update(t_name=t_name)
Teacher.objects.filter(tid=tid).update(t_sex=t_sex)
Teacher.objects.filter(tid=tid).update(t_title=t_title)
Teacher.objects.filter(tid=tid).update(t_education=t_education)
Teacher.objects.filter(tid=tid).update(t_dept=t_dept)
name = put[0]['name']
sex = put[0]['sex']
title = put[0]['title']
education = put[0]['education']
dept = put[0]['dept']
Teacher.objects.filter(tid=tid).update(name=name)
Teacher.objects.filter(tid=tid).update(sex=sex)
Teacher.objects.filter(tid=tid).update(title=title)
Teacher.objects.filter(tid=tid).update(education=education)
Teacher.objects.filter(tid=tid).update(dept=dept)
data = Teacher.objects.filter(tid=tid)[0].to_dict()
return JsonResponse({'code': 200, 'msg': 'success','data':data}, safe=False)
@ -92,7 +94,32 @@ def teacher(request):
def delete(request):
tid = request.GET.get('tid')
Teacher.objects.filter(tid = tid).delete()
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
try:
Teacher.objects.filter(tid = tid).delete()
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
except:
return JsonResponse({'code': 200, 'msg': '删除失败'}, safe=False)
@csrf_exempt
def teaching_resources(request):
pass
@csrf_exempt
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)
else:
return JsonResponse({'code': 200, 'msg': '成绩输入有误'}, safe=False)

Loading…
Cancel
Save