From 12fde8b36df8c9a0a79688dcee53c9eb7c7574d4 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 29 Jun 2011 23:40:20 +0530 Subject: [PATCH] next and prev page working --- edgware/files/views.py | 12 ++++++++++-- edgware/static/js/files/browse.js | 17 +++++++++++++++++ edgware/templates/files/browser.html | 4 ++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/edgware/files/views.py b/edgware/files/views.py index 92cb24b..c1adc94 100644 --- a/edgware/files/views.py +++ b/edgware/files/views.py @@ -12,6 +12,7 @@ from django.views.decorators.csrf import csrf_exempt from ox.django.shortcuts import render_to_json_response from django.shortcuts import get_object_or_404 from models import TYPE_CHOICES +from django.core.paginator import Paginator, InvalidPage, EmptyPage ''' class folder_names(object): @@ -235,7 +236,7 @@ def fileList(request): category = request.POST.get("category", '') typ = request.POST.get("fileType", '') search = request.POST.get("search", '') - page = request.POST.get("page", 1) + page = request.POST.get("page_no", 1) qset = File.objects.all() if category != '': qset = File.filter_category(category, qset) @@ -243,9 +244,16 @@ def fileList(request): qset = File.filter_type(typ, qset) if search != '': qset = File.fts(search, qset) + RESULTS_PER_PAGE = 20 + paginator = Paginator(qset, RESULTS_PER_PAGE) + try: + results = paginator.page(page) + except (EmptyPage, InvalidPage): + results = paginator.page(paginator.num_pages) + files = results.object_list d = {} d['files'] = [] - for f in qset: + for f in files: d['files'].append(f.get_dict()) return render_to_json_response(d) diff --git a/edgware/static/js/files/browse.js b/edgware/static/js/files/browse.js index 7847237..d52e408 100644 --- a/edgware/static/js/files/browse.js +++ b/edgware/static/js/files/browse.js @@ -16,6 +16,23 @@ $(function() { } }, "json"); }); + + $('#prevBtn').click(function() { + var $page_no = $('#page_no'); + var currPage = parseInt($page_no.val()); + if (currPage > 1) { + $page_no.val(currPage - 1); + $('#filterForm').submit(); + } + }); + + $('#nextBtn').click(function() { + var $page_no = $('#page_no'); + var currPage = parseInt($page_no.val()); + $page_no.val(currPage + 1); + $('#filterForm').submit(); + }); + }); function getJQ(f) { diff --git a/edgware/templates/files/browser.html b/edgware/templates/files/browser.html index 7f867f0..56d61f8 100644 --- a/edgware/templates/files/browser.html +++ b/edgware/templates/files/browser.html @@ -11,6 +11,7 @@
{{ filterForm.as_p }}

+

@@ -18,6 +19,9 @@
+
prev
+
next
+