Skip to content
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

Add pagination #137

Closed
wants to merge 2 commits into from
Closed

Conversation

robert-pringle
Copy link

Fixes #59

Pagination is handled like a django ListView, and templates should be designed in the same way.
When pagination is enabled the default build locations for the first page are: build_folder/build_path and /build_folder/build_page_name/1/build_path, with other pages only built in: /build_folder/build_page_name/<page_number>/build_path

Fix issue when page number is 0 inconsistent behaviour was experienced
@coveralls
Copy link

Coverage Status

Coverage remained the same at 80.21% when pulling 75eabb0 on robert-pringle:master into 2c9c495 on datadesk:master.

@robert-pringle
Copy link
Author

Any Interest in this patch?

Copy link

@ociule ociule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great feature, hope it can get merged in!

@dozymoe
Copy link

dozymoe commented Nov 1, 2020

Something I have problem with, self.queryset should be self.get_queryset(), or store the result somewhere and use it as parameter to later method calls.

The default build_path for pagination looks weird to me, I'd prefer something like:

- build_folder/basename.ext
- build_folder/basename-page-2.ext or build_folder/basename/page2.ext

Also the links from pager is not matched, you'd get "?page=2"

@dozymoe
Copy link

dozymoe commented Nov 1, 2020

I think you can use functools.partial to store the result of self.get_queryset()

@dozymoe
Copy link

dozymoe commented Nov 1, 2020

Check https://github.com/dozymoe/django-bakery/commit/5dbc0c46c045e13c082286e85461250fa43ec0b6

I have not updated the test or docs.
Have not fixed the pager links either.

@dozymoe
Copy link

dozymoe commented Nov 1, 2020

Oops. The "?page=N" came from my django templates.

@dozymoe
Copy link

dozymoe commented Nov 1, 2020

Checkout my latest main branch: https://github.com/dozymoe/django-bakery/tree/main

This will create pager url:

{% load bakery %}
<a href="{% pager_url page_obj.next_page_number %}">Next Page</a>

Something I am not clear about, is how Django construct full url, in my code I'd just make something like href="/index.html" but what if Django run under sub-directory in the server, when it should be href="/subdir/index.html".

@robert-pringle
Copy link
Author

robert-pringle commented Nov 1, 2020

@dozymoe

This will create pager url:

{% load bakery %}
<a href="{% pager_url page_obj.next_page_number %}">Next Page</a>

I'd use the standard Django method of adding pagination to a template, the build path is not necessarily the same as the url.
For example if you're using urls without a file extension like "www.example.com/pagename/" this will load the index.html file on most web servers.
{% if page_obj.has_next == True %} <a href="{% url 'url name' page=page_obj.next_page_number %}"/> {% endif %}

@dozymoe
Copy link

dozymoe commented Nov 2, 2020

I think my patch has problem with urls created by Django, as in it won't work with the dev server, still need fixes.

I made https://github.com/dozymoe/frozen-django if anyone interested.

It's dumb, can't export to AWS or static/media files, still a work in progress.
But fit my use-case for now, I am using Django signals to trigger updates.

@palewire palewire closed this Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could the BuildableListView work with pagination?
5 participants