def test_get_page_empty_data(self): query_set = [] page = get_page(query_set, 2, 2) self.assertEqual(page.number, 1) self.assertEqual(page.start_index(), 0) self.assertEqual(page.end_index(), 0) self.assertEqual(page.object_list, [])
def test_get_page_middile(self): query_set = ['data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7'] page = get_page(query_set, 2, 3) self.assertEqual(page.number, 2) self.assertEqual(page.start_index(), 4) self.assertEqual(page.end_index(), 6) self.assertEqual(page.object_list, ['data4', 'data5', 'data6'])
def test_get_page_last_not_exact(self): query_set = ['data1', 'data2', 'data3', 'data4'] page = get_page(query_set, 2, 3) self.assertEqual(page.number, 2) self.assertEqual(page.start_index(), 4) self.assertEqual(page.end_index(), 4) self.assertEqual(page.object_list, ['data4'])
def test_get_page_first(self): query_set = ['data1', 'data2', 'data3', 'data4'] page = get_page(query_set, 1, 2) self.assertEqual(page.number, 1) self.assertEqual(page.start_index(), 1) self.assertEqual(page.end_index(), 2) self.assertEqual(page.object_list, ['data1', 'data2'])
def test_get_page_last(self): query_set = ['data1', 'data2', 'data3', 'data4'] page = get_page(query_set, 2, 2) self.assertEqual(page.number, 2) self.assertEqual(page.start_index(), 3) self.assertEqual(page.end_index(), 4) self.assertEqual(page.object_list, ['data3', 'data4'])
def test_get_page_first_not_exact(self): query_set = ['data1', 'data2', 'data3', 'data4'] page = get_page(query_set, 1, 3) self.assertEqual(page.number, 1) self.assertEqual(page.start_index(), 1) self.assertEqual(page.end_index(), 3) self.assertEqual(page.object_list, ['data1', 'data2', 'data3'])
def test_get_page_middile(self): query_set = [ 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7' ] page = get_page(query_set, 2, 3) self.assertEqual(page.number, 2) self.assertEqual(page.start_index(), 4) self.assertEqual(page.end_index(), 6) self.assertEqual(page.object_list, ['data4', 'data5', 'data6'])
def home(request, page_no=1): notices = Notice.objects.filter(user=request.user) notices_page = get_page(notices, page_no, config.PAGE_SIZE) prefix = reverse("notification.views.home") current_nav = u"通知中心" breadcrumbs = [ {"name": current_nav}, ] return render_template("notification/home.html", request=request, prefix=prefix, \ notices_page=notices_page, breadcrumbs=breadcrumbs, current_nav=current_nav)