lrs update teacher code
scl-branch
lrs 1 year ago
commit 1e084d20f3

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

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
<serverData>
<paths name="root@222.187.226.110:35261">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
</serverData>
</component>
</project>

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

@ -0,0 +1,23 @@
from django.http import JsonResponse
class AuthMiddleware:
"""
验证权限登录中间件
"""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
path = request.path
if path in [
"/login",
]:
response = self.get_response(request)
return response
session = request.session
if not session.get("username") and not session.get("type"):
return JsonResponse({"code": -1, "msg": "not login!"}, status=401)
response = self.get_response(request)
return response

@ -13,9 +13,8 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from API import views
from API.views import *
from django.urls import path
urlpatterns = [
path("students/", views.student)
]

@ -1,7 +1,53 @@
import json
from django.shortcuts import render
from django.http import JsonResponse
from django.http import JsonResponse, HttpResponse
# Create your views here.
from django.views.decorators.csrf import csrf_exempt
from Student.models import *
from teacher.models import Teacher
from EduSystemServer.utils import ResponseUtil
@csrf_exempt
def login(request):
username = json.loads(request.body).get("username")
password = json.loads(request.body).get("password")
_type = json.loads(request.body).get("type")
if _type == "student":
student = Student.objects.filter(username=username,
password=password).first()
if student:
request.session["username"] = student.username
request.session["type"] = "student"
result = ResponseUtil.ok(student.to_dict(), "login success!")
else:
result = {"code": -1, "message": "username or password error!"}
elif _type == "teacher":
teacher = Teacher.objects.filter(username=username,
password=password).first()
if teacher:
request.session["username"] = teacher.username
request.session["type"] = "teacher"
result = ResponseUtil.ok(teacher.to_dict(), "login success!")
else:
result = ResponseUtil.error("username or password error!")
else:
result = ResponseUtil.error("type error!")
return JsonResponse(result)
def student(request):
return JsonResponse({"sid": 1, "sname":"张三"})
@csrf_exempt
def get_user_info(request):
_type = request.GET.get("type")
username = request.GET.get("username")
if _type == "student":
student = Student.objects.filter(username=username).first()
result = ResponseUtil.ok(student.to_dict())
elif _type == "teacher":
teacher = Teacher.objects.filter(username=username).first()
result = ResponseUtil.ok(teacher.to_dict())
else:
result = ResponseUtil.error("type error")
request.session.clear()
return JsonResponse(result)

@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -29,7 +31,6 @@ ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
@ -37,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'API',
'Student',
'teacher',
@ -52,8 +54,29 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
# 'API.middle.AuthMiddleware',
]
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = (
'XMLHttpRequest',
'X_FILENAME',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
'Pragma',
)
ROOT_URLCONF = 'EduSystemServer.urls'
TEMPLATES = [

@ -15,12 +15,16 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
from API.views import login, get_user_info
urlpatterns = [
path('Eduadmin/', admin.site.urls),
path('api/', include(("API.urls", "api"), namespace="api")),
path('student/', include(("Student.urls", "studnet"), namespace="student")),
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('login', login),
path('userinfo', get_user_info),
]

@ -0,0 +1,10 @@
class ResponseUtil:
@staticmethod
def ok(data, message="success!"):
return {"code": 0, "message": message, "data": data}
@staticmethod
def error(message="error!"):
return {"code": -1, "message": message}

@ -1,4 +1,4 @@
# Generated by Django 2.1 on 2023-09-06 14:02
# Generated by Django 2.1 on 2023-09-07 13:49
from django.db import migrations, models
@ -14,8 +14,8 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Admin',
fields=[
('username', models.CharField(max_length=32, primary_key=True, serialize=False, verbose_name='管理员账号')),
('password', models.CharField(max_length=128, verbose_name='管理员密码')),
('username', models.CharField(blank=True, max_length=32, primary_key=True, serialize=False, verbose_name='管理员账号')),
('password', models.CharField(blank=True, max_length=128, verbose_name='管理员密码')),
],
options={
'verbose_name': '管理员',

@ -0,0 +1,23 @@
# Generated by Django 3.2.13 on 2023-09-07 08:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Eduadmin', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='admin',
name='password',
field=models.CharField(blank=True, max_length=128, verbose_name='管理员密码'),
),
migrations.AlterField(
model_name='admin',
name='username',
field=models.CharField(blank=True, max_length=32, primary_key=True, serialize=False, verbose_name='管理员账号'),
),
]

@ -1,4 +1,4 @@
# Generated by Django 2.1 on 2023-09-06 14:01
# Generated by Django 2.1 on 2023-09-07 13:49
from django.db import migrations, models
@ -14,14 +14,14 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Student',
fields=[
('sid', models.IntegerField(primary_key=True, serialize=False, verbose_name='学生编号')),
('s_username', models.CharField(max_length=30, verbose_name='用户名称')),
('s_password', models.CharField(max_length=100, verbose_name='密码')),
('s_name', models.CharField(max_length=100, verbose_name='姓名')),
('s_sex', models.CharField(max_length=4, verbose_name='性别')),
('s_grade', models.IntegerField(verbose_name='年级')),
('s_class_name', models.CharField(max_length=50, verbose_name='班级')),
('s_major', models.CharField(max_length=50, verbose_name='专业名称')),
('sid', models.AutoField(primary_key=True, serialize=False, verbose_name='学生编号')),
('username', models.CharField(blank=True, max_length=30, verbose_name='用户名称')),
('password', models.CharField(blank=True, max_length=100, verbose_name='密码')),
('name', models.CharField(blank=True, max_length=100, verbose_name='姓名')),
('sex', models.CharField(blank=True, max_length=4, verbose_name='性别')),
('grade', models.CharField(blank=True, max_length=20, verbose_name='年级')),
('class_name', models.CharField(blank=True, max_length=50, verbose_name='班级')),
('major', models.CharField(blank=True, max_length=50, verbose_name='专业名称')),
],
options={
'verbose_name': '学生',

@ -0,0 +1,53 @@
# Generated by Django 3.2.13 on 2023-09-07 09:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Student', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='student',
name='s_class_name',
field=models.CharField(blank=True, max_length=50, verbose_name='班级'),
),
migrations.AlterField(
model_name='student',
name='s_grade',
field=models.CharField(blank=True, max_length=20, verbose_name='年级'),
),
migrations.AlterField(
model_name='student',
name='s_major',
field=models.CharField(blank=True, max_length=50, verbose_name='专业名称'),
),
migrations.AlterField(
model_name='student',
name='s_name',
field=models.CharField(blank=True, max_length=100, verbose_name='姓名'),
),
migrations.AlterField(
model_name='student',
name='s_password',
field=models.CharField(blank=True, max_length=100, verbose_name='密码'),
),
migrations.AlterField(
model_name='student',
name='s_sex',
field=models.CharField(blank=True, max_length=4, verbose_name='性别'),
),
migrations.AlterField(
model_name='student',
name='s_username',
field=models.CharField(blank=True, max_length=30, verbose_name='用户名称'),
),
migrations.AlterField(
model_name='student',
name='sid',
field=models.AutoField(primary_key=True, serialize=False, verbose_name='学生编号'),
),
]

@ -4,6 +4,7 @@ from django.db import models
# Create your models here.
class Student(models.Model):
sid = models.AutoField(primary_key=True, verbose_name="学生编号", name="sid")
<<<<<<< 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)
@ -15,6 +16,19 @@ class Student(models.Model):
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
class Meta:
db_table = "student"

@ -3,5 +3,6 @@ from django.urls import path
from .views import *
urlpatterns = [
path("", studnets)
path("", studnets),
path("selectCourse", get_select_course_by_id)
]

@ -5,6 +5,10 @@ from django.http import JsonResponse
from .models import Student
from django.views.decorators.csrf import csrf_exempt
from django.http import QueryDict
from io import BytesIO
from django.http.multipartparser import MultiPartParser
@csrf_exempt
def studnets(request):
if request.method == "POST":
@ -20,10 +24,90 @@ def studnets(request):
print(student.sid)
print(student.to_dict())
student.s_name = request.POST.get("s_name") or ''
student.s_sex = request.POST.get("s_sex") or ''
student.s_grade = request.POST.get("s_grade") or ''
student.s_class_name = request.POST.get("s_class_name") or ''
student.s_major = request.POST.get("s_major") or ''
student.username = request.POST.get("username")
student.password = request.POST.get("password")
student.name = request.POST.get("name")
student.sex = request.POST.get("sex")
student.grade = request.POST.get("grade")
student.class_name = request.POST.get("class_name")
student.major = request.POST.get("major")
student.sid = request.POST.get("sid")
student.save()
response = {"code": 200, "message": "添加成功!", "data": student.to_dict()}
return JsonResponse(response)
elif request.method == "GET":
sid = request.GET.get('sid')
s_name = request.GET.get('s_name')
s_sex = request.GET.get('s_sex')
s_grade = request.GET.get('s_grade')
s_class_name = request.GET.get('s_class_name')
s_major = request.GET.get('s_major')
data = []
if sid:
filtered = Student.objects.filter(sid=sid)
for student in filtered:
data.append(student.to_dict())
elif s_name:
filtered = Student.objects.filter(s_name=s_name)
for student in filtered:
data.append(student.to_dict())
elif s_sex:
filtered = Student.objects.filter(s_sex=s_sex)
for student in filtered:
data.append(student.to_dict())
elif s_grade:
filtered = Student.objects.filter(s_grade=s_grade)
for student in filtered:
data.append(student.to_dict())
elif s_class_name:
filtered = Student.objects.filter(s_class_name=s_class_name)
for student in filtered:
data.append(student.to_dict())
elif s_major:
filtered = Student.objects.filter(s_major=s_major)
for student in filtered:
data.append(student.to_dict())
else:
all_objects = Student.objects.all()
for studnet in all_objects:
data.append(studnet.to_dict())
return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
elif request.method == "DELETE":
parser = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding)
post_dict = parser.parse()
sid = post_dict[0]['sid']
try:
info = Student.objects.filter(sid=sid).get().to_dict()
Student.objects.filter(sid=sid).delete()
response = {"code": 200, "message": "删除成功!", "data": info}
return JsonResponse(response)
except:
response = {"code": 200, "message": "删除失败,未找到学生信息!"}
return JsonResponse(response)
elif request.method == "PUT":
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
sid = put[0]['sid']
s_username = put[0]['s_username']
s_name = put[0]['s_name']
s_sex = put[0]['s_sex']
s_grade = put[0]['s_grade']
s_class_name = put[0]['s_class_name']
s_major = put[0]['s_major']
try:
Student.objects.filter(sid=sid).update(s_username=s_username, s_name=s_name, s_sex=s_sex, s_grade=s_grade,
s_class_name=s_class_name,
s_major=s_major)
except:
Student.objects.create(sid=sid, s_username=s_username, s_name=s_name, s_sex=s_sex, s_grade=s_grade,
s_class_name=s_class_name,
s_major=s_major)
data = Student.objects.filter(sid=sid)[0].to_dict()
return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
student_list = Student.objects.all()
response_json = {"code": 200, "message": "success", "data": []}
for student in student_list:
@ -37,3 +121,5 @@ def studnets(request):
print(xx.split('\r\n'))
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
def get_select_course_by_id(request):
pass

@ -1,4 +1,4 @@
# Generated by Django 2.1 on 2023-09-06 14:01
# Generated by Django 2.1 on 2023-09-07 13:49
from django.db import migrations, models
import django.db.models.deletion
@ -9,8 +9,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('Student', '0001_initial'),
('teacher', '0001_initial'),
('Student', '0001_initial'),
]
operations = [
@ -18,8 +18,8 @@ class Migration(migrations.Migration):
name='Course',
fields=[
('cid', models.AutoField(primary_key=True, serialize=False, verbose_name='课程编号')),
('c_name', models.CharField(max_length=255, verbose_name='课程名称')),
('c_type', models.CharField(max_length=128, verbose_name='课程类型')),
('name', models.CharField(blank=True, max_length=255, verbose_name='课程名称')),
('type', models.CharField(blank=True, max_length=128, verbose_name='课程类型')),
('credit', models.IntegerField(verbose_name='课程学分')),
('tid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='teacher.Teacher')),
],

@ -0,0 +1,23 @@
# Generated by Django 3.2.13 on 2023-09-07 08:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('course', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='course',
name='c_name',
field=models.CharField(blank=True, max_length=255, verbose_name='课程名称'),
),
migrations.AlterField(
model_name='course',
name='c_type',
field=models.CharField(blank=True, max_length=128, verbose_name='课程类型'),
),
]

@ -7,11 +7,15 @@ from Student.models import Student
# Create your models here.
class Course(models.Model):
cid = models.AutoField(primary_key=True, verbose_name="课程编号", name="cid")
c_name = models.CharField(max_length=255, verbose_name="课程名称", name="c_name", blank=True)
type = models.CharField(max_length=128, verbose_name="课程类型", name="c_type", blank=True)
name = models.CharField(max_length=255, verbose_name="课程名称", name="name", blank=True)
type = models.CharField(max_length=128, verbose_name="课程类型", name="type", blank=True)
credit = models.IntegerField(verbose_name="课程学分", name="credit")
tid = models.ForeignKey(Teacher, to_field="tid", on_delete=models.CASCADE, name="tid")
def to_dict(self):
return {"cid": self.cid, "c_name": self.name, "type": self.type, "credit": self.credit,
"tid": self.tid}
class Meta:
db_table = "course"
verbose_name = "课程"
@ -25,7 +29,8 @@ class SC(models.Model):
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}
return {"sid": self.sid, "cid": self.cid, "middle_grade": self.middle_grade, "end_grade": self.end_grade}
class Meta:
db_table = "sc"
verbose_name = "管理员"

@ -0,0 +1,7 @@
from django.urls import path
from course.views import *
urlpatterns = [
path("", courses),
]

@ -1,3 +1,69 @@
from django.shortcuts import render
# Create your views here.
from django.http import JsonResponse
from course.models import *
from django.views.decorators.csrf import csrf_exempt
from io import BytesIO
from django.http.multipartparser import MultiPartParser
@csrf_exempt
def courses(request):
if request.method == "POST":
course = Course()
course.c_name = request.POST.get("c_name")
course.type = request.POST.get('type')
course.credit = request.POST.get("credit")
course.tid = request.POST.get('tid')
course.save()
response = {"code": 200, "message": "添加成功!", "data": course.to_dict()}
return JsonResponse(response)
elif request.method == "GET":
cid = request.GET.get('cid')
c_name = request.GET.get('c_name')
c_type = request.GET.get('type')
tid = request.GET.get('tid')
data = []
if cid:
filtered = Course.objects.filter(cid=cid)
for item in filtered:
data.append(item.to_dict())
elif c_name:
filtered = Course.objects.filter(c_name=c_name)
for item in filtered:
data.append(item.to_dict())
elif c_type:
filtered = Course.objects.filter(type=c_type)
for item in filtered:
data.append(item.to_dict())
elif tid:
filtered = Course.objects.filter(tid=tid)
for item in filtered:
data.append(item.to_dict())
else:
all_objects = Course.objects.all()
for item in all_objects:
data.append(item.to_dict())
return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
elif request.method == "DELETE":
delete = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding).parse()
cid = delete[0]['cid']
try:
info = Course.objects.filter(cid=cid).get().to_dict()
Course.objects.filter(cid=cid).delete()
response = {"code": 200, "message": "删除成功!", "data": info}
return JsonResponse(response)
except:
response = {"code": 200, "message": "删除失败,未找到课程信息!"}
return JsonResponse(response)
elif request.method == "PUT":
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
cid = put[0]['cid']
c_name = put[0]['c_name']
c_type = put[0]['type']
credit = put[0]['credit']
tid = put[0]['tid']
Course.objects.filter(cid=cid).update(c_name=c_name, type=c_type, credit=credit, tid=tid)
data = Course.objects.filter(cid=cid)[0].to_dict()
return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)

@ -1,4 +1,4 @@
# Generated by Django 2.1 on 2023-09-06 14:01
# Generated by Django 2.1 on 2023-09-07 13:49
from django.db import migrations, models
@ -15,11 +15,11 @@ class Migration(migrations.Migration):
name='Teacher',
fields=[
('tid', models.AutoField(primary_key=True, serialize=False, verbose_name='教师编号')),
('t_name', models.CharField(max_length=255, verbose_name='教师名称')),
('t_sex', models.CharField(max_length=128, verbose_name='教师性别')),
('t_title', models.CharField(max_length=128, verbose_name='教师职称')),
('t_education', models.CharField(max_length=128, verbose_name='教师学历')),
('t_dept', models.CharField(max_length=128, verbose_name='教师所属院系')),
('name', models.CharField(blank=True, max_length=255, verbose_name='教师名称')),
('sex', models.CharField(blank=True, max_length=128, verbose_name='教师性别')),
('title', models.CharField(blank=True, max_length=128, verbose_name='教师职称')),
('education', models.CharField(blank=True, max_length=128, verbose_name='教师学历')),
('dept', models.CharField(blank=True, max_length=128, verbose_name='教师所属院系')),
],
options={
'verbose_name': '教师',

@ -0,0 +1,38 @@
# Generated by Django 3.2.13 on 2023-09-07 08:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('teacher', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='teacher',
name='t_dept',
field=models.CharField(blank=True, max_length=128, verbose_name='教师所属院系'),
),
migrations.AlterField(
model_name='teacher',
name='t_education',
field=models.CharField(blank=True, max_length=128, verbose_name='教师学历'),
),
migrations.AlterField(
model_name='teacher',
name='t_name',
field=models.CharField(blank=True, max_length=255, verbose_name='教师名称'),
),
migrations.AlterField(
model_name='teacher',
name='t_sex',
field=models.CharField(blank=True, max_length=128, verbose_name='教师性别'),
),
migrations.AlterField(
model_name='teacher',
name='t_title',
field=models.CharField(blank=True, max_length=128, verbose_name='教师职称'),
),
]

@ -10,6 +10,7 @@ class Teacher(models.Model):
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, "name": self.name, "sex": self.sex, "title": self.title,
"education": self.education, "dept": self.dept}

Loading…
Cancel
Save