Skip to content

Story 2377: Webpage Integration: Implement Pagination to Posts Feed Page#2392

Open
herzog0 wants to merge 10 commits intodevelopfrom
teo/2377-posts-feed-pagination
Open

Story 2377: Webpage Integration: Implement Pagination to Posts Feed Page#2392
herzog0 wants to merge 10 commits intodevelopfrom
teo/2377-posts-feed-pagination

Conversation

@herzog0
Copy link
Copy Markdown
Collaborator

@herzog0 herzog0 commented May 4, 2026

Issue: #2377

Summary & Context

This PR introduces a new V3 pagination component, including custom template tags for dynamic page range calculation and URL generation. It integrates this new component into the posts feed (news list) and provides comprehensive demo examples for various pagination states, ensuring a consistent user experience.

  • Figma link:
  • Link to components/page: localhost:8000/v3/components/#pagination, localhost:8000/news/

Changes

  • Adds new Django template tags (resolve_pagination, pagination_range, page_url) for handling pagination logic, contextual data resolution, and URL construction with query parameters and anchor links.
  • Implements the V3 pagination UI with a new CSS stylesheet (pagination.css) and a dedicated HTML include (_pagination.html), featuring page numbers, ellipses, and chevron navigation.
  • Integrates the new pagination component into the EntryListView (posts feed) by enabling paginate_by and including the pagination template.
  • Expands the V3ComponentDemoView to include a new section demonstrating various pagination scenarios, with parameters for current page, total pages, and anchor scrolling, allowing for easy testing of different pagination states.
  • Ensures the pagination component always renders correctly, even when only a single page of content is available.

‼️ Risks & Considerations ‼️

  • There're no Figma definitions for how the styles should behave depending on the amount of pages and the selected page. The implementation is based on my opinion and some feedback from the refinement meeting;
  • There's no Figma for dark mode, tablet and mobile variants. I'm basing myself off of the foundations mappings;

Screenshots

image

Mobile:
image

Desktop:
image

Dark mode:
image

Self-review Checklist

  • Tag at least one team member from each team to review this PR
  • Link this PR to the related GitHub Project ticket

Frontend

  • UI implementation matches Figma design
  • Tested in light and dark mode
  • Responsive / mobile verified
  • Accessibility checked (keyboard navigation, etc.)
  • Ensure design tokens are used for colors, spacing, typography, etc. – No hardcoded values
  • Test without JavaScript (if applicable)
  • No console errors or warnings

@herzog0 herzog0 requested review from jlchilders11 and julhoang May 4, 2026 20:04
@herzog0 herzog0 linked an issue May 4, 2026 that may be closed by this pull request
@herzog0 herzog0 changed the title Adds V3 pagination component and posts feed integration Story 2377: Webpage Integration: Implement Pagination to Posts Feed Page May 4, 2026
@herzog0 herzog0 marked this pull request as ready for review May 4, 2026 22:47
Copy link
Copy Markdown
Collaborator

@julhoang julhoang left a comment

Choose a reason for hiding this comment

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

@herzog0 This works really great! Just 1 small responsive issue I noticed is when we have a small mobile screen – I'm testing using iPhone SE and when the pagination is the longest it could get like below, we'll get an overflow:

Image

Perhaps we shouldhave the mobile pagination only have a sliding window of +/- 1 item instead of 2 🤔

Copy link
Copy Markdown
Collaborator

@jlchilders11 jlchilders11 left a comment

Choose a reason for hiding this comment

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

Couple of small changes to better leverage the paginator in the template. See https://docs.djangoproject.com/en/6.0/topics/pagination/ for details on using these functions.

Comment thread core/templatetags/pagination_tags.py Outdated
Comment thread templates/v3/includes/_pagination.html Outdated
Comment thread templates/v3/includes/_pagination.html Outdated
herzog0 added 5 commits May 8, 2026 11:03
- `core/templatetags/pagination_tags.py`: new `pagination_range` tag
  (computes window ±2 with leading/trailing ellipsis) and `page_url`
  tag (builds URL preserving all existing query params)
- `static/css/v3/pagination.css`: component styles using design tokens;
  active page uses --color-surface-weak, inactive --color-text-secondary,
  ellipsis --color-text-tertiary, border-radius --border-radius-xl (12px)
- `templates/v3/includes/_pagination.html`: reusable partial; works in
  standard ListView context (page_obj/paginator) or in isolation via
  pagination_current/pagination_total/pagination_page_param params
- `news/views.py`: enable pagination (paginate_by=10) on EntryListView
- `templates/v3/posts_list.html`: include pagination partial below posts
- `templates/v3/examples/_v3_example_section.html`: 7 clickable demo
  examples (24-page and small-page sets) driven by URL query params
- `core/views.py`: add demo_pagination context data to V3ComponentDemoView
…o context

Django evaluates filter arguments eagerly, so `|default:page_obj.number`
raises VariableDoesNotExist when page_obj is not in context (e.g. demo page).

Replace the broken `{% with current=...|default:page_obj.number %}` pattern
with a new `resolve_pagination` template tag that reads page_obj/paginator
from context safely via Python's dict.get().
Each demo example div gets a unique id (pag-pg24a, etc.) plus
scroll-margin-top so the browser snaps to the right position.
Every page link in the partial now appends #anchor when pagination_anchor
is set, keeping the user in the right section after a page change.

The posts feed does not pass pagination_anchor so its links are unchanged.
pagination_range now returns [1] for num_pages=1 instead of hiding.
The partial guard changed from total > 1 to total >= 1 so the nav
always renders (both chevrons disabled, single page number shown).
@herzog0 herzog0 force-pushed the teo/2377-posts-feed-pagination branch from 87ad8fe to 8af1f7e Compare May 8, 2026 14:04
@herzog0 herzog0 force-pushed the teo/2377-posts-feed-pagination branch from d19388f to 15db8f8 Compare May 8, 2026 14:46
@herzog0 herzog0 requested review from jlchilders11 and julhoang May 8, 2026 15:22
Copy link
Copy Markdown
Collaborator

@julhoang julhoang left a comment

Choose a reason for hiding this comment

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

It looks great and works great, this is a super neat implementation – thanks @herzog0 ! ✨🙌

Copy link
Copy Markdown
Collaborator

@jlchilders11 jlchilders11 left a comment

Choose a reason for hiding this comment

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

Couple more small django things.

num_pages = page.paginator.num_pages
current = page.number

if num_pages <= 1:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's leverage django hero and use page.has_previous()

return items


@register.simple_tag(takes_context=True)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I didn't catch this last time, but django actually has a tag we can use for a lot of this logic already: https://docs.djangoproject.com/en/6.0/ref/templates/builtins/#querystring

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.

Webpage Integration: Implement Pagination to Posts Feed Page

3 participants