next and prev page working

This commit is contained in:
Sanj 2011-06-29 23:40:20 +05:30
parent d638ffb50d
commit 12fde8b36d
3 changed files with 31 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from django.views.decorators.csrf import csrf_exempt
from ox.django.shortcuts import render_to_json_response from ox.django.shortcuts import render_to_json_response
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from models import TYPE_CHOICES from models import TYPE_CHOICES
from django.core.paginator import Paginator, InvalidPage, EmptyPage
''' '''
class folder_names(object): class folder_names(object):
@ -235,7 +236,7 @@ def fileList(request):
category = request.POST.get("category", '') category = request.POST.get("category", '')
typ = request.POST.get("fileType", '') typ = request.POST.get("fileType", '')
search = request.POST.get("search", '') search = request.POST.get("search", '')
page = request.POST.get("page", 1) page = request.POST.get("page_no", 1)
qset = File.objects.all() qset = File.objects.all()
if category != '': if category != '':
qset = File.filter_category(category, qset) qset = File.filter_category(category, qset)
@ -243,9 +244,16 @@ def fileList(request):
qset = File.filter_type(typ, qset) qset = File.filter_type(typ, qset)
if search != '': if search != '':
qset = File.fts(search, qset) 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 = {}
d['files'] = [] d['files'] = []
for f in qset: for f in files:
d['files'].append(f.get_dict()) d['files'].append(f.get_dict())
return render_to_json_response(d) return render_to_json_response(d)

View File

@ -16,6 +16,23 @@ $(function() {
} }
}, "json"); }, "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) { function getJQ(f) {

View File

@ -11,6 +11,7 @@
<form id="filterForm"> <form id="filterForm">
{{ filterForm.as_p }} {{ filterForm.as_p }}
<p> <p>
<input type="hidden" name="page_no" id="page_no" value="1" />
<input type="submit" value="Submit" id="submitFilter" /> <input type="submit" value="Submit" id="submitFilter" />
</p> </p>
</form> </form>
@ -18,6 +19,9 @@
<div id="fileList"> <div id="fileList">
</div> </div>
<div id="prevBtn">prev</div>
<div id="nextBtn">next</div>
</div> </div>
<div id="previewPane"> <div id="previewPane">