-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#98 fixed the "land on last page by default" bug + test
- Loading branch information
Showing
4 changed files
with
39 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Union | ||
|
||
from django.core.paginator import Page, Paginator | ||
from django.db.models import QuerySet | ||
from django.http import HttpRequest | ||
|
||
from ..appsettings import MENU_ITEM_PAGINATION | ||
from ..models import Audio, Video | ||
|
||
DEFAULT_PAGE_KEY = "p" | ||
|
||
pagination_template = "wagtailadmin/shared/ajax_pagination_nav.html" | ||
|
||
|
||
def paginate( | ||
request: HttpRequest, | ||
items: Union[QuerySet[Audio], QuerySet[Video]], | ||
page_key: str = DEFAULT_PAGE_KEY, | ||
per_page: int = MENU_ITEM_PAGINATION, | ||
) -> tuple[Paginator, Page]: | ||
paginator: Paginator = Paginator(items, per_page) | ||
page = paginator.get_page(request.GET.get(page_key)) | ||
return paginator, page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters