-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blog pagination #346
base: master
Are you sure you want to change the base?
Blog pagination #346
Conversation
try: | ||
page_number = int(page_number) | ||
except ValueError: | ||
page_number = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to run black & isort!
In backend/ directory, run:
poetry run black .
poetry run isort .
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.
|
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.