Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Add option SHOW_FIRST_PAGE_WHEN_INVALID #24

Open
barsch opened this issue Feb 2, 2019 · 1 comment · May be fixed by #27
Open

Add option SHOW_FIRST_PAGE_WHEN_INVALID #24

barsch opened this issue Feb 2, 2019 · 1 comment · May be fixed by #27

Comments

@barsch
Copy link

barsch commented Feb 2, 2019

It would be very useful to have an option to default to the first page if hitting a wrong page object.

I suggest to basically replace https://github.com/pydanny/dj-pagination/blob/master/dj_pagination/templatetags/pagination_tags.py#L186-L196 with something like this:

    try:
        page_obj = paginator.page(request.page(page_suffix))
    except InvalidPage:
        if INVALID_PAGE_RAISES_404:
            raise Http404(
                "Invalid page requested.  If DEBUG were set to "
                + "False, an HTTP 404 page would have been shown instead."
            )
        if SHOW_FIRST_PAGE_WHEN_INVALID
            # fallback to first page
            page_obj = paginator.page(1)
        else:
            context[key] = []
            context["invalid_page"] = True
            return ""
@sampaccoud
Copy link

sampaccoud commented Feb 27, 2020

I had the same issue and thought it might be even better to trigger a permanent redirect to page 1.
I proposed a PR to @pydanny #27 🤞

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants