Merge branch 'master' of https://bdgit.educoder.net/pfzs9fyia/EduSystem
lrs update teacher codescl-branch
commit
1e084d20f3
@ -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>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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
|
Binary file not shown.
@ -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)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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='管理员账号'),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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='学生编号'),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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='课程类型'),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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='教师职称'),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue