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