def list_entries( request, blog_slug=None, page_num=1 ): ''' renders requested page, a list of date-ordred entries ''' blog = Blog.get_blog(blog_slug) pages = LaidbackPaginator(blog.get_entries(), blog.page_length) # curry it up to save typing! route = curry(route_template, blog_slug=blog.slug) context = RequestContext(request, { 'blog': blog, 'page': pages.page(page_num), 'multiblog': multiblog_enabled, }) context['base_template'] = select_template( route('base') ) return render_to_response( route('entry_list'), {}, context )
def show_category(request, blog_slug=None, category_slug=None, page_num=1): ''' lists entries under category specified by category_slug ''' blog = Blog.get_blog(blog_slug) category = get_object_or_404(Category, blog=blog, slug=category_slug) entries = Entry.live.filter( category=category ) pages = LaidbackPaginator(entries, blog.page_length) route = curry(route_template,extraname=category.slug,blog_slug=blog.slug) context = RequestContext(request, { 'blog': blog, 'category': category, 'page': pages.page(page_num), 'multiblog': multiblog_enabled, }) context['base_template'] = select_template( route('base') ) return render_to_response( route('category_details'), {}, context )
class UtilLaidbackPaginatorPageMethodTest(TestCase): def setUp(self): self.dummy_data = range(0,20) self.PAGE_BY = 5 self.pages = LaidbackPaginator(self.dummy_data, self.PAGE_BY) def test_should_return_normally(self): p = self.pages.page('2').object_list self.assertEquals(p, [5, 6, 7, 8, 9]) def test_should_tolerate_nonsense_arg(self): p = self.pages.page(None).object_list self.assertEquals(p, [0, 1, 2, 3, 4]) def test_should_accept_over_ranged_arg(self): p = self.pages.page(10).object_list self.assertEquals(p, [15, 16, 17, 18, 19]) def test_should_accept_under_ranged_arg(self): p = self.pages.page(0).object_list self.assertEquals(p, [15, 16, 17, 18, 19])
def setUp(self): self.dummy_data = range(0,20) self.PAGE_BY = 5 self.pages = LaidbackPaginator(self.dummy_data, self.PAGE_BY)