Paginatorの確認
def test001(request):
'''ページネーターの動作確認'''
objects = ['john', 'paul', 'george', 'ringo']
p = Paginator(objects, 2)
try:
page1 = p.page(3)
except EmptyPage, e:
print e
page1 = p.page(1)
c = dict(
has_next=page1.has_next(),
has_previous=page1.has_previous(),
has_other_pages=page1.has_other_pages(),
next_page_number=page1.next_page_number(),
previous_page_number=page1.previous_page_number(),
start_index=page1.start_index(),
end_index=page1.end_index(),
object_list=page1.object_list,
number=page1.number,
test=None,
)
c = simplejson.dumps(c, sort_keys=True, indent=2 * ' ')
return HttpResponse(c, mimetype='application/json')
すべてのページをjsonにする
def test002(request):
'''ページネーターの動作確認'''
objects = ['john', 'paul', 'george', 'ringo', 'yyy']
p = Paginator(objects, 2)
pageRange = p.page_range
cc = {}
for ipage in pageRange:
page1 = p.page(ipage)
c = dict(
has_next=page1.has_next(),
has_previous=page1.has_previous(),
has_other_pages=page1.has_other_pages(),
next_page_number=page1.next_page_number(),
previous_page_number=page1.previous_page_number(),
start_index=page1.start_index(),
end_index=page1.end_index(),
object_list=page1.object_list,
number=page1.number,
test=None,
)
cc[ipage] = c
ccJson = simplejson.dumps(cc, sort_keys=True, indent=2 * ' ')
return HttpResponse(ccJson, mimetype='application/json')