def get(self, request): objects_page = create_paginated_page( query_set=VideoPage.not_removed_objects.filter(published=True).order_by('-id'), page_number=request.GET.get('page') or 1, objects_per_page=VIDEO_PAGES_PER_PAGE ) return self.render_to_response({'objects_page': objects_page })
def get(self, request, username): author = get_object_or_404(User, username=username) objects_page = create_paginated_page( query_set=VideoPage.not_removed_objects.filter(author=author).order_by('-id'), page_number=request.GET.get('page') or 1, objects_per_page=VIDEO_PAGES_PER_PAGE ) return self.render_to_response({'author_name': author.username, 'objects_page': objects_page })
def get(self, request, tag): tag = urllib.unquote(unicode(tag)) tag = get_object_or_404(Tag, name=tag) videopages = TaggedItem.objects.get_by_model(VideoPage, tag) objects_page = create_paginated_page( query_set=videopages.filter(removed=False).order_by('-id'), page_number=request.GET.get('page') or 1, objects_per_page=VIDEO_PAGES_PER_PAGE ) return self.render_to_response({'objects_page': objects_page })
def test_empty_page(self): page = create_paginated_page(query_set=[], page_number=10000, objects_per_page=self.OBJECTS_PER_PAGE) self.assertEquals(1, page.paginator.num_pages)
def test_wrong_page_number(self): page = create_paginated_page(query_set=self.objects, page_number='JDJDJD', objects_per_page=self.OBJECTS_PER_PAGE) self.assertEqual(self.PAGE_NUMBER, page.number)
def test_create_paginator(self): page = create_paginated_page(query_set=self.objects, page_number=self.PAGE_NUMBER, objects_per_page=self.OBJECTS_PER_PAGE) self.assertEqual(len(self.objects), page.paginator.count) self.assertEqual(self.PAGE_NUMBER, page.number)