Open
Conversation
katajakasa
reviewed
Apr 1, 2024
| try: | ||
| page_number = int(page_number) | ||
| except ValueError: | ||
| page_number = 1 |
Member
There was a problem hiding this comment.
Consider splitting the request.GET and exception handler to a separate function, get_page_number() or somesuch.
| # We will pass this boolean as extra data to the template for simplicity | ||
| # It's used to determine whether to render pagination links or not: | ||
| needs_pagination = paginator.count > paginator.per_page | ||
| return {"entries": entries, "needs_pagination": needs_pagination, "page_range": paginator.page_range, "page_number": current_page.number, "num_pages": paginator.num_pages} |
Member
There was a problem hiding this comment.
Remember to run black & isort!
In backend/ directory, run:
poetry run black .
poetry run isort .
Member
|
Btw, to navigate to specific post, you could do something like ?pageWith= and then just load from database the count of posts where event matches the instanssi event id, and ID is smaller than or equal to the currently searched blog post. That would give you the count of posts before the post yo want to show, and you could count the page from that. Then you could just browse to correct page and highlight the post. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Initial version of the blog pagination. This uses a GET parameter "p" for page number (like https://instanssi.org/2024/?p=2 if there are over 10 blog entries)
This gets the basic job of pagination done.
URLs to individual blog entries to be fixed in the future:
Linking to individual blog entry with its id on the URL (like https://instanssi.org/2024/#1) is not very good. If the blog entry is later on another page (because newer entries are added and it falls to another page) then old enough URLs (in social media) will become non-functional when the element with the certain id (1 in this example) does not exist on the first page (default) anymore.
We will need to address this case of linking to an individual blog entry separately with a different view. Then just link to that view's URL instead of using the HTML element id in the URL and the problem goes away.
Another option to fix the case would be to invert the page numbering so the first 10 ids would always be on page nr 1 and not the latest 10 on page nr 1. Then the default page would be whatever was the highest page number. Also the initial page load would need to set the p GET parameter correctly for links to entries to work also in the future (the user would copy the whole thing like ?p=1#1 from the address bar).
However, most likely the first option is still the best and the most logical solution to use in here. We will want to have that "read a single blog post" view anyway.