def custom(request): all_count = UserInfo.objects.all().count() current_page = request.GET.get('page') page_info = pager.PageInfo(current_page,all_count,10,'/custompage.html') user_list=UserInfo.objects.all()[page_info.start():page_info.end()] # print(user_list) # return HttpResponse('123') return render(request,'custompage.html',{'user_list':user_list,'page_info':page_info})
def author_list(request): all_count = models.Author.objects.all().count() page_info = pager.PageInfo(request.GET.get('page'), all_count, 10, 'author_list.html', 11) author_obj = models.Author.objects.all()[page_info.start():page_info.end()] return render(request, 'author_list.html', { 'author_obj': author_obj, 'page_info': page_info })
def book_list(request): if request.method == "GET": all_count = models.Book.objects.all().count() page_info = pager.PageInfo(request.GET.get('page'), all_count, 10, 'Book_List.html', 11) Book_list = models.Book.objects.all()[page_info.start():page_info.end( )] return render(request, "Book_List.html", { 'Book_list': Book_list, 'page_info': page_info })
def get(self, req): # 每10页显示一张内容 # current_page=req.GET.get('page') # current_page=int(current_page) # per_page=10 # start=(current_page-1)*per_page # end=current_page*per_page # result=models.UserInfo.objects.all()[start:end] current_page = req.GET.get('page') #获取所有元素的个数 all_count = models.UserInfo.objects.all().count() page_info = pager.PageInfo(current_page, all_count, 10, '/custom.html') result = models.UserInfo.objects.all()[page_info.start():page_info.end( )] return render(req, 'custom.html', { 'result': result, 'page_list': page_info })
def student(request): """ 学生管理首页 """ # 检验用户是否登录 tk = request.COOKIES.get('ticket') if not tk: return redirect('/sign/') # 获得url url = '/student/?' if request.GET.get('per_page'): url = '/student/?per_page=' + request.GET.get('per_page') + '&' # 展示学生信息 if request.GET.get('sort') == "desc": # 倒排 url = "/student/?sort=desc&" slist = sqlheper.get_list( "select student.id,name,student_id,sex,telephone,major_name,class.title from student left join class on class.id=class_id order by student.id DESC", []) else: slist = sqlheper.get_list( "select student.id,name,student_id,sex,telephone,major_name,class.title from student left join class on class.id=class_id order by student.id", []) student_number = len(sqlheper.get_list("select * from student", [])) all_count = student_number # 学生表数据条数 current_page = 1 if request.GET.get('page'): current_page = int(request.GET.get('page')) # 当前页码 per_page = 10 # 默认每页数据条数 if request.GET.get('per_page'): per_page = int(request.GET.get('per_page')) # 新建一个分页器 page_info = pager.PageInfo(current_page, all_count, per_page, url) # 将学生表切片,只展示当前页所需学生信息 start, end = page_info.start(), page_info.end() student_list_obj = StudentList(slist, start, end) major = sqlheper.get_list('select major_name from major', []) return render(request, 'student.html', {'student_list_obj': student_list_obj, 'per_page': per_page, 'page_info': page_info, 'class_list': json.dumps(student_list_obj.class_list), 'major': major, 'url': request.get_full_path() })
def course(request): """ 课程管理首页 """ # 检验用户是否登录 tk = request.COOKIES.get('ticket') if not tk: return redirect('/sign/') # 获得url url = '/course/?' if request.GET.get('per_page'): url = '/course/?per_page=' + request.GET.get('per_page') + '&' # 展示课程信息 if request.GET.get('sort') == "desc": # 倒排 url = "/course/?sort=desc&" clist = sqlheper.get_list( "select course.id,course_name,teacher.name,credit,status from course left join teacher on course.teacher_number=teacher.teacher_number order by course.id DESC", []) else: # 正序 clist = sqlheper.get_list( "select course.id,course_name,teacher.name,credit,status from course left join teacher on course.teacher_number=teacher.teacher_number order by course.id", []) course_number = len(sqlheper.get_list("select * from course", [])) all_count = course_number # 课程表数据条数 current_page = 1 # 默认当前页 if request.GET.get('page'): current_page = int(request.GET.get('page')) # 当前页码 per_page = 10 # 默认每页数据条数 if request.GET.get('per_page'): per_page = int(request.GET.get('per_page')) # 新建一个分页器 page_info = pager.PageInfo(current_page, all_count, per_page, url) # 将学生表切片,只展示当前页所需学生信息 start, end = page_info.start(), page_info.end() course_list_obj = CourseList(clist, start, end) return render(request, 'course.html', {'course_list_obj': course_list_obj, 'per_page': per_page, 'page_info': page_info, 'teacher_list': json.dumps(course_list_obj.teacher_list), 'url': request.get_full_path() })