|
|
@ -4,12 +4,10 @@ from django.contrib import messages
|
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger # 分页组件
|
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger # 分页组件
|
|
|
|
from app01 import models
|
|
|
|
from app01 import models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
# Create your views here.
|
|
|
|
def index(request):
|
|
|
|
def index(request):
|
|
|
|
return render(request, 'homepage.html')
|
|
|
|
return render(request, 'homepage.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def login(request):
|
|
|
|
def login(request):
|
|
|
|
if request.method == 'GET':
|
|
|
|
if request.method == 'GET':
|
|
|
|
return render(request, 'login.html', )
|
|
|
|
return render(request, 'login.html', )
|
|
|
@ -37,11 +35,9 @@ def login(request):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return HttpResponse('failed')
|
|
|
|
return HttpResponse('failed')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def manage_homepage(request):
|
|
|
|
def manage_homepage(request):
|
|
|
|
return render(request, 'homepage_admin.html')
|
|
|
|
return render(request, 'homepage_admin.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def manage_student(request):
|
|
|
|
def manage_student(request):
|
|
|
|
search_key = request.GET.get('key', '')
|
|
|
|
search_key = request.GET.get('key', '')
|
|
|
|
students = models.StuInfo.objects.filter(name__contains=search_key).all()
|
|
|
|
students = models.StuInfo.objects.filter(name__contains=search_key).all()
|
|
|
@ -56,7 +52,6 @@ def manage_student(request):
|
|
|
|
students = paginator.page(paginator.num_pages)
|
|
|
|
students = paginator.page(paginator.num_pages)
|
|
|
|
return render(request, 'student_manage.html', locals())
|
|
|
|
return render(request, 'student_manage.html', locals())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def manage_course(request):
|
|
|
|
def manage_course(request):
|
|
|
|
search_key = request.GET.get('key', '')
|
|
|
|
search_key = request.GET.get('key', '')
|
|
|
|
courses = models.CourseInfo.objects.filter(course_name__contains=search_key).all()
|
|
|
|
courses = models.CourseInfo.objects.filter(course_name__contains=search_key).all()
|
|
|
@ -71,7 +66,6 @@ def manage_course(request):
|
|
|
|
courses = paginator.page(paginator.num_pages)
|
|
|
|
courses = paginator.page(paginator.num_pages)
|
|
|
|
return render(request, 'course_manage.html',locals())
|
|
|
|
return render(request, 'course_manage.html',locals())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StuForm(ModelForm):
|
|
|
|
class StuForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
class Meta:
|
|
|
|
model = models.StuInfo
|
|
|
|
model = models.StuInfo
|
|
|
@ -83,7 +77,6 @@ class StuForm(ModelForm):
|
|
|
|
for field in self.fields.values():
|
|
|
|
for field in self.fields.values():
|
|
|
|
field.widget.attrs['class'] = 'form-control'
|
|
|
|
field.widget.attrs['class'] = 'form-control'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_student(request):
|
|
|
|
def add_student(request):
|
|
|
|
if request.method == 'GET':
|
|
|
|
if request.method == 'GET':
|
|
|
|
form = StuForm()
|
|
|
|
form = StuForm()
|
|
|
@ -97,7 +90,6 @@ def add_student(request):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return render(request, 'student_add.html', {'form': form})
|
|
|
|
return render(request, 'student_add.html', {'form': form})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def edit_student(request, sid):
|
|
|
|
def edit_student(request, sid):
|
|
|
|
queryset = models.StuInfo.objects.filter(id=sid).first()
|
|
|
|
queryset = models.StuInfo.objects.filter(id=sid).first()
|
|
|
|
if request.method == 'GET':
|
|
|
|
if request.method == 'GET':
|
|
|
@ -143,7 +135,6 @@ def add_course(request):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return render(request, 'course_add.html', {'form': form})
|
|
|
|
return render(request, 'course_add.html', {'form': form})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def edit_course(request, cid):
|
|
|
|
def edit_course(request, cid):
|
|
|
|
queryset = models.CourseInfo.objects.filter(id=cid).first()
|
|
|
|
queryset = models.CourseInfo.objects.filter(id=cid).first()
|
|
|
|
if request.method == 'GET':
|
|
|
|
if request.method == 'GET':
|
|
|
@ -158,17 +149,11 @@ def edit_course(request, cid):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return render(request, 'course_edit.html', {'form': form})
|
|
|
|
return render(request, 'course_edit.html', {'form': form})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_course(request, cid):
|
|
|
|
def delete_course(request, cid):
|
|
|
|
models.CourseInfo.objects.filter(id=cid).first().delete()
|
|
|
|
models.CourseInfo.objects.filter(id=cid).first().delete()
|
|
|
|
return redirect('/manage/course/list/')
|
|
|
|
return redirect('/manage/course/list/')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def manage_select(request):
|
|
|
|
def manage_select(request):
|
|
|
|
# student_objs = models.StuInfo.objects.all()
|
|
|
|
|
|
|
|
# queryset = {}
|
|
|
|
|
|
|
|
# for obj in student_objs:
|
|
|
|
|
|
|
|
# queryset[obj.name] = obj.course.all()
|
|
|
|
|
|
|
|
# 获取当前页数
|
|
|
|
# 获取当前页数
|
|
|
|
selects = models.Select.objects.all()
|
|
|
|
selects = models.Select.objects.all()
|
|
|
|
print(selects)
|
|
|
|
print(selects)
|
|
|
@ -182,7 +167,6 @@ def manage_select(request):
|
|
|
|
selects = paginator.page(paginator.num_pages)
|
|
|
|
selects = paginator.page(paginator.num_pages)
|
|
|
|
return render(request, 'select_manage.html', locals())
|
|
|
|
return render(request, 'select_manage.html', locals())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_select(request, id):
|
|
|
|
def delete_select(request, id):
|
|
|
|
models.Select.objects.filter(id=id).first().delete()
|
|
|
|
models.Select.objects.filter(id=id).first().delete()
|
|
|
|
return redirect('/manage/select/list/')
|
|
|
|
return redirect('/manage/select/list/')
|
|
|
|