add Vue Dist file

master
bettleChen 1 year ago
parent 8daef8924f
commit 37d597cd2f

@ -13,10 +13,11 @@ class JWTMiddleware:
def __call__(self, request): def __call__(self, request):
# 检查请求的路径是否是登录路由,如果是,放行 # 检查请求的路径是否是登录路由,如果是,放行
if request.path == '/login': if request.path == '/login' \
response = self.get_response(request) or request.path == "/index" \
return response or request.path == "/" \
if request.path.startswith("/admin"): or request.path.startswith("/admin")\
or request.path.startswith("/static"):
response = self.get_response(request) response = self.get_response(request)
return response return response
# 从请求头中获取 Token # 从请求头中获取 Token

@ -87,7 +87,7 @@ ROOT_URLCONF = 'EduSystemServer.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'dist')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
@ -154,6 +154,10 @@ USE_TZ = False
# https://docs.djangoproject.com/en/2.2/howto/static-files/ # https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'dist'),
)
CORS_ALLOW_CREDENTIALS = True CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True CORS_ORIGIN_ALLOW_ALL = True

@ -14,12 +14,15 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include, re_path
from django.views.generic import TemplateView
from API.views import login, get_user_info from API.views import login, get_user_info
urlpatterns = [ urlpatterns = [
path(r'', TemplateView.as_view(template_name='index.html')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api/', include(("API.urls", "api"), namespace="api")), path('api/', include(("API.urls", "api"), namespace="api")),
path('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")), path('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")),

@ -3,7 +3,6 @@ from django.urls import path
from .views import * from .views import *
urlpatterns = [ urlpatterns = [
path("", studnets),
path("search", search_student), path("search", search_student),
path("selectCourse", select_course), path("selectCourse", select_course),
path("add", add_student), path("add", add_student),

@ -4,121 +4,15 @@ from django.core import serializers
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
from django.http import JsonResponse
from course.models import SC, Course from course.models import SC, Course
from .models import Student
from EduSystemServer.utils import * from EduSystemServer.utils import *
from Student.models import Student
from .models import Student from .models import Student
from django.views.decorators.csrf import csrf_exempt 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 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
@csrf_exempt
def studnets(request):
if request.method == "POST":
try:
request_data = request.POST
student = Student.objects.filter(sid=request_data.get("sid")).first()
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()
response = ResponseUtil.ok(student.to_dict(), "更新成功!")
return JsonResponse(response)
except Exception as E:
return JsonResponse(ResponseUtil.error(E))
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:
response_json["data"].append(student.to_dict())
return JsonResponse(response_json)
elif request.method == 'DELETE':
params = QueryDict(request.body)
key = next(iter(params.keys())) # 获取键名
value = params.get(key) # 获取值
xx = str(value).split('-')[0]
print(xx.split('\r\n'))
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
@csrf_exempt @csrf_exempt
@permission(allowed_roles=["admin", "teacher"]) @permission(allowed_roles=["admin", "teacher"])
def add_student(request): def add_student(request):

@ -3,7 +3,6 @@ from django.urls import path
from course.views import * from course.views import *
urlpatterns = [ urlpatterns = [
path("", courses),
path("getCourseById", get_course_by_student_id), path("getCourseById", get_course_by_student_id),
path("deleteSelectCourse", delete_select_course), path("deleteSelectCourse", delete_select_course),
path("seacherCourse", search_course), path("seacherCourse", search_course),

@ -4,73 +4,10 @@ from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.db.models import F, Subquery, Max from django.db.models import F, Subquery, Max
from django.shortcuts import render from django.shortcuts import render
# Create your views here.
from django.http import JsonResponse
from EduSystemServer.utils import * from EduSystemServer.utils import *
from course.models import * from course.models import *
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from io import BytesIO
from django.http.multipartparser import MultiPartParser
from django.core import serializers
@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":
teacher_name = request.GET.get("tName")
course_name = request.GET.get("cName")
course_type = request.GET.get("cType")
current_page = request.GET.get("currentPage")
if not teacher_name == "" or not teacher_name is None:
filter_course = Course.objects.filter(tid__name__contains=teacher_name)
if not course_name == "" or not course_name is None:
filter_course = Course.objects.filter(tid__course__name=course_name)
if not course_type == "" or not course_type is None:
filter_course = Course.objects.filter(tid__course__type=course_type)
filter_course = filter_course.values("tid__course__name", "tid__name", "tid__course__type", "tid__course__credit",
"tid__title", "tid__education", "tid__dept", "cid").all()
paginator = Paginator(filter_course, 10)
try:
courses = paginator.page(current_page).object_list
except PageNotAnInteger:
courses = paginator.page(1)
except EmptyPage:
courses = paginator.page(paginator.num_pages).object_list
result = ResponseUtil.ok(json.loads(serializers.serialize("json", courses)), "success!")
result["pageTotal"] = paginator.count
result["pageNum"] = paginator.num_pages
return JsonResponse(result)
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)
def search_course(request): def search_course(request):
@ -87,10 +24,10 @@ def search_course(request):
if not teacher_name == "" and teacher_name is not None: if not teacher_name == "" and teacher_name is not None:
filter_course = Course.objects.filter(tid__name__contains=teacher_name) filter_course = Course.objects.filter(tid__name__contains=teacher_name)
if not course_name == "" and course_name is not None: if not course_name == "" and course_name is not None:
filter_course = Course.objects.filter(tid__course__name__contains=course_name) filter_course = Course.objects.filter(name__contains=course_name)
if not course_type == "" and course_type is not None: if not course_type == "" and course_type is not None:
filter_course = Course.objects.filter(tid__course__type__contains=course_type) filter_course = Course.objects.filter(type__contains=course_type)
filter_course = filter_course.values("tid__course__name", "tid__name", "tid__course__type", "tid__course__credit", filter_course = filter_course.values("name", "tid__name", "type", "credit",
"tid__title", "tid__education", "tid__dept", "cid").all() "tid__title", "tid__education", "tid__dept", "cid").all()
paginator = Paginator(filter_course, 10) paginator = Paginator(filter_course, 10)
try: try:
@ -124,7 +61,7 @@ def get_course_by_student_id(request):
result = ResponseUtil.ok(data) result = ResponseUtil.ok(data)
return JsonResponse(result) return JsonResponse(result)
@permission(allowed_roles=["student"])
def delete_select_course(request): def delete_select_course(request):
""" """
删除选课 删除选课

@ -0,0 +1 @@
.login-module{margin-top:60px;position:absolute;right:500px;text-align:center;width:30%}.el-header{background-color:#b3c0d1;color:#333;line-height:60px}.transfer-footer{margin-left:20px;padding:6px 5px}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -0,0 +1,19 @@
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" href="/static/favicon.ico">
<title>front</title>
<script defer="defer" src="/static/js/chunk-vendors.0bcf2d54.js"></script>
<script defer="defer" src="/static/js/app.8637dce5.js"></script>
<link href="/static/css/chunk-vendors.10dd4e95.css" rel="stylesheet">
<link href="/static/css/app.34ccc13b.css" rel="stylesheet">
</head>
<body>
<noscript><strong>We're sorry but front doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong></noscript>
<div id="app"></div>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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

@ -14,120 +14,3 @@ from django.http import QueryDict
from course.models import Course,SC from course.models import Course,SC
from Student.models import Student from Student.models import Student
import json import json
@csrf_exempt
def teacher(request):
if request.method == "POST":
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')
sex = request.GET.get('sex')
title = request.GET.get('title')
education = request.GET.get('education')
dept = request.GET.get('dept')
data = []
if name:
filtered = Teacher.objects.filter(name=name)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif sex:
filtered = Teacher.objects.filter(sex=sex)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif title:
filtered = Teacher.objects.filter(title=title)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif education:
filtered = Teacher.objects.filter(education=education)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
elif dept:
filtered = Teacher.objects.filter(dept=dept)
for teacher_x in filtered:
data.append(teacher_x.to_dict())
else:
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)
elif request.method == "DELETE":
parser = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding)
posdict = parser.parse()
print(posdict)
tid = int(posdict[0]['tid'])
print(tid)
try:
info = Teacher.objects.filter(tid=tid).get().to_dict()
Teacher.objects.filter(tid=tid).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()
# request.PUT = put[0]
print(put)
tid = put[0]['tid']
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)
def delete(request):
tid = request.GET.get('tid')
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