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

Conversation

@sampaccoud
Copy link

@sampaccoud sampaccoud commented Feb 27, 2020

Purpose

When the number of items in a collection varies, it happens that urls, already shared on the web, point to a page that is now invalid.

Up to now, dj-pagination only allowed to either render nothing or raise a 404 page.

Another good practice to prevent broken links is to redirect to the first page with a 301 http code.

Proposal

  • Refactor default settings to allow overriding them in tests
  • Add new setting PAGINATION_INVALID_PAGE_TRIGGERS_301. When set to True, invalid pages raise an PaginationRedirect exception when an invalid page is requested
  • Modify the PaginationMiddleware to handle PaginationRedirect exceptions and trigger the redirect
  • Add tests to secure the new redirect feature

Fixes #24

sampaccoud added 2 commits February 27, 2020 09:01
The way settings are imported in the pagination_tags module makes
it difficult to override them in tests because they are evaluated
on import. I propose define defaults in a defaults.py file and
actually evaluate the setting via a getter only when they are used.
When the number of items in a collection varies, it happens that urls,
already shared on the web, point to a page that is now invalid.
Up to now dj-pagination only allowed to either render nothing or raise
a 404 page. Another  good practice to prevent broken links is to
redirect to the first page with a 301 http code.
@sampaccoud
Copy link
Author

Hey @pydanny, are you still maintaining this project? We have a few improvements to make so we propose to take over its maintenance at https://github.com/openfun? Otherwise we need to fork it or vendor it in our project. What do you think is the best solution?

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 this pull request may close these issues.

Add option SHOW_FIRST_PAGE_WHEN_INVALID

1 participant