def Host_list(request,page): user_dict = request.session.get('is_login',None) per_item = common.try_int(request.COOKIES.get('pager_num',10),10) #操作数据库进行分页 page = common.try_int(page,1) count = models.Asset.objects.all().count() pageobj = html_helper.PageInfo(page,count,per_item) result = models.Asset.objects.all()[pageobj.start:pageobj.end] page_string = html_helper.Pager(page,pageobj.pages_all_count) ret = {'data':result,'count':count,'page':page_string,'username':user_dict['user']} response = render(request,'app01/host_list.html',ret) response.set_cookie('pager_num',per_item) return response
def freshwebchat(request): ret = {'last_num':'','data':''} try: last_num = try_int(request.POST.get('last_num')) if last_num == 0: data = list(Chat.objects.all()[-10:-1]) else: data = list(Chat.objects.all()[last_num:]) ret['last_num'] = data[-1]['id'] ret['data'] = data print ret return HttpResponse(json.dumps(ret, CJsonEncode)) except Exception, e: return HttpResponse()
def index(request,page): #操作数据库,进行分页 ''' try: page = int(page) except BaseException,e: page = 1 ''' page = common.try_int(page,1) #将char转换为int,如果不能转换就成为默认值 count = models.Host.objects.all().count() pageObj = http_helper.PageInfo(page,count) result = models.Host.objects.all()[pageObj.start():pageObj.end()] page_string = http_helper.Pager(page, pageObj.all_page_count()) ret = {'data':result,'count':count,'page':page_string} return render_to_response('index.html',ret)
def index(request, page): #操作数据库进行分页 ''' page = int(page) ''' print request.COOKIES page = common.try_int(page, 1) count = models.Host.objects.all().count() pageObj = html_helper.PageInfo(page, count, 5) result = models.Host.objects.all()[pageObj.start:pageObj.end] page_string = html_helper.Pager(page, pageObj.all_page_count) ret = {'data': result, 'count': count, 'page': page_string} #return render_to_response('index.html',ret) response = render_to_response('index.html', ret) response.set_cookie('k1', 'v1') return response
def index(request, page): ''' try: page = int(page) except Exception,e: page = 1 page = int(page) ''' page = common.try_int(page, 1) per_item = 5 ''' start = (page-1)*per_item end = page*per_item temp = divmod(count, per_item) if temp[1] == 0: all_page_count = temp[0] else: all_page_count = temp[0] + 1 ''' ''' page_html = [] #显示首页 first_html = "<a href='/index/%d'>首页</a>" %(1,) page_html.append(first_html) #显示上一页 if page <= 1: prv_html = "<a href='#'>上一页</a>" else: prv_html = "<a href='/index/%d'>上一页</a>" %(page-1,) page_html.append(prv_html) #显示每一个分页的页数 for i in range(all_page_count): if page == i+1: a_html = "<a class='selected' href='/index/%d'>%d</a>" % (i + 1, i + 1) else: a_html = "<a href='/index/%d'>%d</a>" % (i + 1, i + 1) page_html.append(a_html) #显示下一页 next_html = "<a href='/index/%d'>下一页</a>" %(page+1,) page_html.append(next_html) #显示尾页 end_html = "<a href='/index/%d'>尾页</a>" %(all_page_count) page_html.append(end_html) page = mark_safe(''.join(page_html)) ''' count = models.Host.objects.all().count() # count = models.Host.objects.all().count() # result = models.Host.objects.all() pageobj = page_helper.PageInfo(page, count, 20) result = models.Host.objects.all()[pageobj.start:pageobj.end] page_string = page_helper.page(page, pageobj.all_page_count) ret = {'data': result, 'count': count, 'page': page_string} return render_to_response('index.html', ret)
def index(request,page): #操作数据库,进行分页 #第一页0-4 page = 1 #第二页5-10 page = 2 #第三页10-15 page = 3 #(page-1)*5 page*5 #per_item = common.try_int(request.COOKIES.get('pager_num',10),10) per_item = common.try_int(request.COOKIES.get('pager_num',None),10) print per_item page = common.try_int(page, 1) #page = int(page) count = models.Host.objects.all().count() ''' per_item = 5 start = (page-1)*per_item end = (page*per_item) temp = divmod(count, per_item) if temp[1]==0: all_page_count = temp[0] else: all_page_count = temp[0]+1 ''' pageObj = htmlhelper.PageInfo(page,count,per_item) result = models.Host.objects.all()[pageObj.start:pageObj.end] ''' page_html = [] first_html = "<a href='/index/%d'>首页</a>" %(1,) page_html.append(first_html) if page <= 1: prev_html = "<a href='#'>上一页</a>" else: prev_html = "<a href='/index/%d'>上一页</a>" %(page-1,) page_html.append(prev_html) for i in range(all_page_count): if page == i+1: a_html = "<a class = 'selected' href='/index/%d'>%d</a>" %(i+1,i+1) else: a_html = "<a href='/index/%d'>%d</a>" %(i+1,i+1) page_html.append(a_html) next_page = "<a href='/index/%d'>下一页</a>" %(page+1,) page_html.append(next_page) last_html = "<a href='/index/%d'>尾页</a>" %(all_page_count,) page_html.append(last_html) page = mark_safe(''.join(page_html)) ''' page_string = htmlhelper.Pager(page, pageObj.all_page_count) ret = {'data':result,'count':count,'page':page_string,'list':'10'} response = render_to_response('index.html',ret) response.set_cookie('pager_num',per_item) #设置COOKIE return response