File: custom.py

package info (click to toggle)
python-django 3%3A6.0~alpha1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,204 kB
  • sloc: python: 370,694; javascript: 19,376; xml: 211; makefile: 187; sh: 28
file content (35 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django.core.paginator import AsyncPage, AsyncPaginator, Page, Paginator


class ValidAdjacentNumsPage(Page):
    def next_page_number(self):
        if not self.has_next():
            return None
        return super().next_page_number()

    def previous_page_number(self):
        if not self.has_previous():
            return None
        return super().previous_page_number()


class ValidAdjacentNumsPaginator(Paginator):
    def _get_page(self, *args, **kwargs):
        return ValidAdjacentNumsPage(*args, **kwargs)


class AsyncValidAdjacentNumsPage(AsyncPage):
    async def anext_page_number(self):
        if not await self.ahas_next():
            return None
        return await super().anext_page_number()

    async def aprevious_page_number(self):
        if not await self.ahas_previous():
            return None
        return await super().aprevious_page_number()


class AsyncValidAdjacentNumsPaginator(AsyncPaginator):
    def _get_page(self, *args, **kwargs):
        return AsyncValidAdjacentNumsPage(*args, **kwargs)