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 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)

View File

@ -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) {

View File

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