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
Use an own paginator #646
Use an own paginator #646
Conversation
The current pagination creates links for every page, which does not work anymore for many pages. Use instead an own paginator, which creates the following pagination control: < 1 ... 5 6 7 8 9 10 11 12 13 14 ... 10 >
Codecov Report
@@ Coverage Diff @@
## master #646 +/- ##
==========================================
+ Coverage 68.84% 69.06% +0.22%
==========================================
Files 88 89 +1
Lines 4439 4471 +32
==========================================
+ Hits 3056 3088 +32
Misses 1383 1383
Continue to review full report at Codecov.
|
Changing slugs is now supported, but links pointing to the article are not updated.
src/wiki/core/wiki_paginate.py
Outdated
super(WikiPaginator, self).__init__(*args, **kwargs) | ||
|
||
def _get_page(self, *args, **kwargs): | ||
self.curPage = super(WikiPaginator, self)._get_page(*args, **kwargs) |
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.
This assignment contract is too implicit. It means that page_range
is broken if _get_page
hasn't been called. Isn't there a way to just call this method directly from page_range
?
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.
@benjaoming Calling _get_page() from page_range() unfortunately does not work.
Source from the django paginator (django/core/paginator.py):
class Paginator(object):
def _get_page(self, *args, **kwargs):
"""
Returns an instance of a single page. This hook can be used by
subclasses to use an alternative to the standard :cls:`Page` object.
"""
return Page(*args, **kwargs)
class Page(collections.Sequence):
def __init__(self, object_list, number, paginator):
self.object_list = object_list
self.number = number
self.paginator = paginator
I.e. the page number is required. And that is exactly what is needed here in the
first place. Based on that I would say that it is guaranteed that _get_page()
is called before page_range().
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.
I tried reordering this a bit
- We don't overwrite a weak internal method (the single underscore denotes to avoid this)
- renamed
curPage
to something with underscores, camelCase isn't used in Python normally :)
It's in floemker#4
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.
More efficient is always good (int instead of a Page object). Committed.
Seems necessary and timely, great idea! Made a PR on your branch and added a review comment. |
…ber context accessing
Rename wiki.core.wiki_paginate to wiki.core.paginator, refac page number context accessing
The current pagination creates links for every page, which does not work
anymore for many pages. Use instead an own paginator, which creates the
following pagination control:
I.e. prev and next links, a link to the first and to the last page, and links
to the current page plus by default four surrounding pages.