示例#1
0
文件: post.py 项目: zgwdg/white
    def get_published_posts_page(self, page=1, perpage=10, category=None):
        cid = None
        if category:
            real_category = self.category_repo.find_by_slug(category)
            if not real_category:
                return Paginator([], 0, page, perpage, '/category/' + category)
            cid = real_category.cid

        total = self.post_repo.category_count(cid)
        pages = self.post_repo.get_published_posts(page, perpage, cid)
        url = 'category/' + category if category else '/posts'
        pagination = Paginator(pages, total, page, perpage, url)
        return total, pagination
示例#2
0
文件: page.py 项目: zgwdg/white
 def page(self, status, page=1, perpage=10):
     total = self.page_repo.count(status)
     pages = self.page_repo.paginate(page, perpage, status)
     if status:
         url = '/admin/page/status/' + status
     else:
         url = '/admin/page'
     pagination = Paginator(pages, total, page, perpage, url)
     return pagination
示例#3
0
class PaginatorTest(unittest.TestCase):
    def setUp(self):
        result = [_ for _ in range(1, 10)]
        self.p = Paginator(result, 100, 10, 5, '/test')

    def test_next_link(self):
        self.assertEqual(str(self.p.next_link('next')),
                         '<a href="/test/11">next</a>')
        self.p.page = 22
        self.assertEqual(str(self.p.next_link('next')), '')

    def test_pre_link(self):
        self.assertEqual(str(self.p.pre_link('pre')),
                         '<a href="/test/9">pre</a>')
        self.p.page = 1
        self.assertEqual(str(self.p.pre_link('pre')), '')

    def test_iter(self):
        for _ in range(1, 9):
            next(self.p)
        self.assertEqual(next(self.p), 9)
        self.assertEqual(self.p._index, 9)
        self.assertRaises(StopIteration, lambda: next(self.p))

    def test_len(self):
        self.assertEqual(9, len(self.p))

    def test_links(self):

        self.assertTrue(self.p.links().startswith(
            '<a href="/test">First</a><a href="/test/9">Previous</a><a href="/test/7">7</a>'
        ))
        self.p.page = 0
        self.assertEqual(
            self.p.links(),
            '<a href="/test/1">1</a><a href="/test/2">2</a><a href="/test/3">3</a><a href="/test/4">4</a><a href="/test/1">Next</a> <a href="/test/20">Last</a>'
        )
        self.p.page = 22
        self.assertEqual(
            self.p.links(),
            '<a href="/test">First</a><a href="/test/21">Previous</a><a href="/test/19">19</a><a href="/test/20">20</a>'
        )
示例#4
0
class PaginatorTest(unittest.TestCase):

    def setUp(self):
        result = [_ for _ in range(1, 10)]
        self.p = Paginator(result, 100, 10, 5, '/test')

    def test_next_link(self):
        self.assertEqual(str(self.p.next_link('next')), '<a href="/test/11">next</a>')
        self.p.page = 22
        self.assertEqual(str(self.p.next_link('next')), '')

    def test_pre_link(self):
        self.assertEqual(str(self.p.pre_link('pre')), '<a href="/test/9">pre</a>')
        self.p.page = 1
        self.assertEqual(str(self.p.pre_link('pre')), '')

    def test_iter(self):
        for _ in range(1, 9):
            next(self.p)
        self.assertEqual(next(self.p), 9)
        self.assertEqual(self.p._index, 9)
        self.assertRaises(StopIteration, lambda: next(self.p))

    def test_len(self):
        self.assertEqual(9, len(self.p))

    def test_links(self):

        self.assertTrue(self.p.links().startswith(
            '<a href="/test">First</a><a href="/test/9">Previous</a><a href="/test/7">7</a>'))
        self.p.page = 0
        self.assertEqual(
            self.p.links(), '<a href="/test/1">1</a><a href="/test/2">2</a><a href="/test/3">3</a><a href="/test/4">4</a><a href="/test/1">Next</a> <a href="/test/20">Last</a>')
        self.p.page = 22
        self.assertEqual(
            self.p.links(), '<a href="/test">First</a><a href="/test/21">Previous</a><a href="/test/19">19</a><a href="/test/20">20</a>')
示例#5
0
文件: post.py 项目: zgwdg/white
 def page(self, page=1, perpage=10, category=None):
     total = self.post_repo.count(category)
     pages = self.post_repo.paginate(page, perpage, category)
     pagination = Paginator(pages, total, page, perpage, '/admin/post')
     return pagination
示例#6
0
文件: post.py 项目: zgwdg/white
    def lists(self, page=1, perpage=10):
        total = self.post_repo.count()
        pages = self.post_repo.paginate(page, perpage)
        pagination = Paginator(pages, total, page, perpage, '/posts')

        return total, pagination
示例#7
0
文件: post.py 项目: zgwdg/white
 def search(self, key, page, perpage=10):
     pages = self.post_repo.search(key, page, perpage)
     total = self.post_repo.serach_count(key)
     pagination = Paginator(pages, total, page, perpage, '/admin/post')
     return pagination
示例#8
0
 def setUp(self):
     result = [_ for _ in range(1, 10)]
     self.p = Paginator(result, 100, 10, 5, '/test')
示例#9
0
 def setUp(self):
     result = [_ for _ in range(1, 10)]
     self.p = Paginator(result, 100, 10, 5, '/test')
示例#10
0
文件: category.py 项目: zgwdg/white
 def page(self, page=1, perpage=10):
     total = self.category_repo.count()
     pages = self.category_repo.paginate(page, perpage)
     pagination = Paginator(pages, total, page, perpage, '/admin/category')
     return pagination
示例#11
0
文件: comment.py 项目: zgwdg/white
 def page(self, status, page=1, perpage=10):
     total = self.comment_repo.count()
     pages = self.comment_repo.paginate(page, perpage, status)
     pagination = Paginator(pages, total, page, perpage, '/admin/comment')
     return pagination
示例#12
0
 def get_user_page(self, user):
     return Paginator([user], 1, 1, 5, '/admin/user')
示例#13
0
 def page(self, page, perpage=5):
     total = self.repo.count()
     users = self.repo.take(page, perpage)
     page = Paginator(users, total, page, perpage, '/admin/user')
     return page
示例#14
0
 def field_page(self, page=1, perpage=10):
     total = self.extend_repo.count()
     pages = self.extend_repo.paginate(page, perpage)
     pagination = Paginator(pages, total, page, perpage,
                            '/admin/extend/field')
     return pagination