-
Notifications
You must be signed in to change notification settings - Fork 26
Story 2377: Webpage Integration: Implement Pagination to Posts Feed Page #2392
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
Open
herzog0
wants to merge
12
commits into
develop
Choose a base branch
from
teo/2377-posts-feed-pagination
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9ea3574
feat: implement V3 pagination component and wire up to posts feed
herzog0 37d9680
fix: avoid VariableDoesNotExist when pagination_current is set in dem…
herzog0 0f7dba4
feat: scroll back to demo paginator after page navigation
herzog0 01b801e
feat: always render pagination, even on a single page
herzog0 a44e8fd
fix: border color
herzog0 3d696b1
chore: improve layout for smaller screen sizes
herzog0 6970093
chore: make code more concise
herzog0 c1b33df
chore: improve code legibility
herzog0 6e32794
chore: use Django's native paginator
herzog0 987d149
fix: rollback to previous elided page impl
herzog0 b149dc7
chore: refactor tag to use built-in querystring tag
herzog0 901f704
fix: always show pagination, regardless of the amount of pages
herzog0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from django import template | ||
| from django.core.paginator import Paginator | ||
|
|
||
| register = template.Library() | ||
|
|
||
|
|
||
| @register.simple_tag(takes_context=True) | ||
| def resolve_pagination(context, current=None, total=None): | ||
| """Return a Django Page object resolved from context or explicit overrides. | ||
|
|
||
| In a ListView context, returns page_obj directly. | ||
| In isolated/demo usage, creates a real Paginator from the given values. | ||
| """ | ||
| page_obj = context.get("page_obj") | ||
|
|
||
| if isinstance(current, int) and isinstance(total, int): | ||
| paginator = Paginator(range(1, total + 1), 1) | ||
| return paginator.page(max(1, min(current, paginator.num_pages))) | ||
|
|
||
| if page_obj is not None: | ||
| return page_obj | ||
|
|
||
| return Paginator([], 1).page(1) | ||
|
|
||
|
|
||
| @register.simple_tag | ||
| def pagination_range(page, window=2): | ||
| """Return an elided page range for the given Page object. | ||
|
|
||
| Always uses an ellipsis for any gap (even a single page), unlike Django's | ||
| built-in get_elided_page_range which fills single-page gaps with the page | ||
| number. Each element is either an integer or '…'. | ||
| """ | ||
| num_pages = page.paginator.num_pages | ||
| current = page.number | ||
|
|
||
| if num_pages <= 1: | ||
| return list(range(1, num_pages + 1)) | ||
|
|
||
| window_start = max(2, current - window) | ||
| window_end = min(num_pages - 1, current + window) | ||
|
|
||
| items = [1] | ||
| if window_start > 2: | ||
| items.append("…") | ||
| items.extend(range(window_start, window_end + 1)) | ||
| if window_end < num_pages - 1: | ||
| items.append("…") | ||
| items.append(num_pages) | ||
| return items | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Pagination component | ||
| * Token hierarchy: semantics.css → themes.css (dark overrides) | ||
| * Usage: _pagination.html | ||
| * | ||
| * Two navs are rendered: --wide (±2 window) and --narrow (±1 window). | ||
| * CSS toggles which one is visible based on viewport width. | ||
| * display:none removes both from the visual layer and the a11y tree. | ||
| */ | ||
|
|
||
| .pagination { | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: center; | ||
| align-items: center; | ||
| gap: var(--space-default); | ||
| padding: var(--space-large) 0; | ||
| list-style: none; | ||
| margin: 0; | ||
| } | ||
|
|
||
| /* ── Shared button styles ── */ | ||
|
|
||
| .pagination__item { | ||
| display: flex; | ||
| } | ||
|
|
||
| .pagination__link, | ||
| .pagination__chevron { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: 40px; | ||
| padding: 0 var(--space-large); | ||
| border: 1px solid transparent; | ||
| border-radius: var(--border-radius-xl); | ||
| font-family: var(--font-sans); | ||
| font-size: var(--font-size-small); | ||
| font-weight: var(--font-weight-regular); | ||
| line-height: var(--line-height-default); | ||
| color: var(--color-text-secondary); | ||
| text-decoration: none; | ||
| transition: background-color 0.15s ease; | ||
| } | ||
|
|
||
| /* ── Page number links ── */ | ||
|
|
||
| .pagination__link:hover { | ||
| background-color: var(--color-surface-mid); | ||
| border-color: var(--color-stroke-weak); | ||
| color: var(--color-text-primary); | ||
| } | ||
|
|
||
| .pagination__link--active { | ||
| background-color: var(--color-surface-weak); | ||
| border-color: var(--color-stroke-weak); | ||
| color: var(--color-text-primary); | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| /* ── Ellipsis ── */ | ||
|
|
||
| .pagination__ellipsis { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: 40px; | ||
| padding: 0 var(--space-default); | ||
| font-family: var(--font-sans); | ||
| font-size: var(--font-size-small); | ||
| font-weight: var(--font-weight-regular); | ||
| color: var(--color-text-tertiary); | ||
| user-select: none; | ||
| } | ||
|
|
||
| /* ── Chevron navigation ── */ | ||
|
|
||
| .pagination__chevron { | ||
| width: 20px; | ||
| height: 20px; | ||
| padding: 0; | ||
| border: none; | ||
| color: var(--color-icon-primary); | ||
| } | ||
|
|
||
| .pagination__chevron--disabled { | ||
| color: var(--color-text-tertiary); | ||
| pointer-events: none; | ||
| cursor: default; | ||
| } | ||
|
|
||
| /* ── Responsive visibility ── */ | ||
|
|
||
| .pagination-nav--narrow { | ||
| display: none; | ||
| } | ||
|
|
||
| @media (max-width: 767px) { | ||
| .pagination-nav--wide { | ||
| display: none; | ||
| } | ||
|
|
||
| .pagination-nav--narrow { | ||
| display: block; | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| {% load pagination_tags %} | ||
| {% comment %} | ||
| Pagination component. | ||
|
|
||
| Standard usage (from ListView — page_obj and paginator are in context): | ||
| {% include "v3/includes/_pagination.html" %} | ||
|
|
||
| Isolated / demo usage: | ||
| {% include "v3/includes/_pagination.html" with pagination_current=5 pagination_total=24 %} | ||
|
|
||
| Parameters: | ||
| pagination_current int – current page number (required for isolated use) | ||
| pagination_total int – total number of pages (required for isolated use) | ||
| pagination_anchor str – optional HTML id; appended as #fragment to every | ||
| page link so the browser scrolls back to the component | ||
| {% endcomment %} | ||
|
|
||
| {% resolve_pagination pagination_current pagination_total as pag %} | ||
| {% pagination_range pag 2 as pages_wide %} | ||
| {% pagination_range pag 1 as pages_narrow %} | ||
| {% if pag.has_previous %}{% querystring page=pag.previous_page_number as prev_url %}{% endif %} | ||
| {% if pag.has_next %}{% querystring page=pag.next_page_number as next_url %}{% endif %} | ||
|
|
||
| {% include "v3/includes/_pagination_nav.html" with pages=pages_wide css_class="pagination-nav--wide" %} | ||
| {% include "v3/includes/_pagination_nav.html" with pages=pages_narrow css_class="pagination-nav--narrow" %} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <nav class="pagination-nav {{ css_class }}" aria-label="Pagination"> | ||
| <ol class="pagination"> | ||
|
|
||
| <li class="pagination__item"> | ||
| {% if pag.has_previous %} | ||
| <a href="{{ prev_url }}{% if pagination_anchor %}#{{ pagination_anchor }}{% endif %}" class="pagination__chevron" aria-label="Previous page" rel="prev"> | ||
| {% include "includes/icon.html" with icon_name="chevron-left" icon_size=20 %} | ||
| </a> | ||
| {% else %} | ||
| <span class="pagination__chevron pagination__chevron--disabled" aria-disabled="true" aria-label="Previous page"> | ||
| {% include "includes/icon.html" with icon_name="chevron-left" icon_size=20 %} | ||
| </span> | ||
| {% endif %} | ||
| </li> | ||
|
|
||
| {% for item in pages %} | ||
| <li class="pagination__item"> | ||
| {% if item == "…" %} | ||
| <span class="pagination__ellipsis" aria-hidden="true">…</span> | ||
| {% elif item == pag.number %} | ||
| <a href="{% querystring page=item %}{% if pagination_anchor %}#{{ pagination_anchor }}{% endif %}" class="pagination__link pagination__link--active" aria-current="page" aria-label="Page {{ item }}">{{ item }}</a> | ||
| {% else %} | ||
| <a href="{% querystring page=item %}{% if pagination_anchor %}#{{ pagination_anchor }}{% endif %}" class="pagination__link" aria-label="Go to page {{ item }}">{{ item }}</a> | ||
| {% endif %} | ||
| </li> | ||
| {% endfor %} | ||
|
|
||
| <li class="pagination__item"> | ||
| {% if pag.has_next %} | ||
| <a href="{{ next_url }}{% if pagination_anchor %}#{{ pagination_anchor }}{% endif %}" class="pagination__chevron" aria-label="Next page" rel="next"> | ||
| {% include "includes/icon.html" with icon_name="chevron-right" icon_size=20 %} | ||
| </a> | ||
| {% else %} | ||
| <span class="pagination__chevron pagination__chevron--disabled" aria-disabled="true" aria-label="Next page"> | ||
| {% include "includes/icon.html" with icon_name="chevron-right" icon_size=20 %} | ||
| </span> | ||
| {% endif %} | ||
| </li> | ||
|
|
||
| </ol> | ||
| </nav> |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.