Story 2378: Webpage Integration: Posts Feed - #2568
Open
ycanales wants to merge 3 commits into
Open
Conversation
The page-tree fixture was local to test_commands.py. Register pages.tests.fixtures so the feed tests can reuse it, and add the two pieces they need on top: a default Site (pytest runs with --no-migrations, so Wagtail's initial data never exists and page.url returns None without one) and a PostPage factory. The factory indexes each page explicitly because indexing is queued with transaction.on_commit, which never runs under the django_db fixture.
…o the posts feed The feed rendered posts and post type pills, but the search box sat outside the form and the library dropdown was fed a context variable no view set, so neither did anything. The pills navigated with window.location.assign, discarding every other query parameter, and zero results rendered nothing at all. Search, pills, library and author are now one GET form writing to ?q=, ?type=, ?library= and ?author=, parsed and validated by PostFeedFilters. Filters run as plain queryset filters and, when a term is present, are handed to Wagtail search through a pk subquery: the backend rejects StreamField lookups outright and tag lookups without a FilterField, and returns SearchResults rather than a queryset. PostPage gains search_fields covering body text, summary, post type, tags and author name; body text is stripped of markup so a search for "p" does not match every rich text post. Zero results render an empty state, plus up to three posts from the selected library with the search term dropped. Submitting the form drops ?page=, which is what resets pagination. The header nav now points at the Wagtail feed. EntryListView keeps serving legacy Entry rows on the v2 template rather than sharing a context contract with it. Existing posts need ./manage.py update_index once per environment before they are searchable.
The dropdown dispatches field-change while setting `selected`, before Alpine has written it to the hidden input the form submits, so choosing a library submitted an empty `library=` and the feed came back unfiltered. Defer the submit a tick. Also pass the request to the nav's feed-page lookup: without it Page.url falls back to a fully qualified URL once a second Site exists, so the nav rendered an absolute href where every other link is a path. Both found by the E2E spec, neither visible to the view tests.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue: #2378
Summary & Context
Makes the posts feed's controls actually work: search, the library filter, a header that reflects the filter state, URL-driven state, an empty state, and a user card wired to real data. Before this PR the search box sat outside the form and did nothing, the library dropdown was fed a context variable no view set (so it rendered empty), the post-type pills navigated with
window.location.assignand discarded every other query parameter, and zero results rendered a bare heading with nothing under it.Stacked on #2562 (
jc/2376-post-detail-page), which movestagsontoPostPage. Review that one first.Changes
Search
search_fieldstoPostPagecovering body text,summary, post type, tag name and slug, and the author's display name.titleis already indexed byPage.search_fields.PostPage.search_body, which runs the StreamField throughget_searchable_content()and strips markup. Indexing the raw block would store HTML, so a search for "p" would match every rich-text post through its<p>tags.AttributeError: 'KeyTransform' object has no attribute 'target'and a tag lookup withFilterFieldError, and.search()returnsSearchResultsrather than a queryset, soselect_related/prefetch_relatedhave to be applied before it.Filters and feed state
pages/feed.pyholding the content-type table (moved out ofpages/models.py) andPostFeedFilters, a frozen dataclass that parses and validates?q=,?type=,?library=and?author=. Every value is resolved to a real object there, so nothing raw from the querystring can reach the feed header. Unknown values degrade to the unfiltered feed.POST_CONTENT_TYPES, resolving the# TODOthat was already in the file._PostContentTypegainslabel(plural, for the pill) andheader_label(singular, for the header), because neither matchescontent_type: the header would otherwise read "Blogpost Posts".disabled. They currently navigate to a bare URL, which silently behaves like "All".library_filter_options()intolibraries/utils.py, shared withEntryListView's old copy. Labelled withdisplay_nameso the dropdown matches the header wording ("Boost.Beast", not "Beast").Template
actiondrops the current querystring, which is what resets pagination:pageis not a form field, so any submit returns to page 1.window.location.assignblock. Submission is now declarative Alpine:field-changeand pillchangecallrequestSubmit(), and Enter submits explicitly (the search field's own submit button disables itself on an empty box, so without that a user could not clear a search).field-changesubmit is deferred with$nextTick. The dropdown dispatches the event as it setsselected, before Alpine has written it to the hidden input the form submits, so submitting immediately sent an emptylibrary=. Caught by the E2E spec, not by the unit tests.<noscript>Filter button and the native<select>fallback both still submit.?author=in a hidden input, so the first pill click does not silently drop it.Empty state
templates/v3/includes/_post_empty_state.htmland the{% else %}branch that_post_list_card.htmlnever had, plus.post-empty-statestyles ported from the library page's treatment.User card
badge_name='Bug Catcher'androle='Contributor', and dropbadge_icon_src, which_user_card.htmldoes not accept and so never rendered. Passrole=u.roleinstead.#. It now reads Sign Up Now and opens the signup page. Heading and copy come from the include's own defaults, which already match the AC verbatim.Routing
/news/, the legacyEntrylist, which rendered the same v3 template from a different context; the two would have had to share a context contract.EntryListViewdrops back to its v2 template and keeps serving legacy entries.posts_feed_url(request)passes the request through toget_urlso the nav renders a path rather than the fully qualified URLPage.urlfalls back to once a second Site exists.Tests
pages/: search per indexed field, each filter, every filter combination, the six header strings, pagination, the empty state and its fallback, URL-driven state, the user card in both auth states, and v3 flag gating. Plus a query-count guard, since each card readsitem.authoranditem.tag.pages/tests/fixtures.py(registered inconftest.py) with the page tree, a default Site and aPostPagefactory. The factory indexes each page explicitly: indexing is queued withtransaction.on_commit, which never runs under thedjango_dbfixture, so every search test would otherwise return zero rows with no error.tests/posts-feed.spec.tsin website-v2-e2e, 16 tests at desktop and mobile. The corpus cannot be created through the UI (the create form submits a draft into moderation, and a draft never renders in the feed), sonpm run seednow also writes it into the page tree.Rejected alternatives
FilterFields so the tag filter survives.search(). The pk subquery needs none, and aFilterFieldon tags would make a post-search.filter()merely pass validation, reintroducing join duplicates.DISTINCTis not available as a fix either: it conflicts with the rankORDER BYthe backend injects.icontainsQ-filter instead of Wagtail search, aslibraries/api.pydoes. It needs no index rebuild, but gives no relevance ranking and cannot reach StreamField body text, which is the bulk of what people search for. The issue's dev note asks forqs.search(...)and that is what this does.tags__slugfor the library filter.tagged_items__tag__slugis used instead: same SQL, but it resolves against the concretePostPagetable under either tag arrangement, so it survives a merge with branches whereTaggedContent.content_objectstill points atwagtailcore.Page(theretags__slugraisesProgrammingError: column pages_postpage.id does not exist).LIMIT 1per request, and a cache would need invalidating on slug change and would leak between tests through the shared Redis. The query-count guard innews/tests/test_views.pymoves from 10 to 11 for it../manage.py update_indexmust run once per environment on deploy. Signals only index onpost_save, so everyPostPagecreated before this lands is invisible to search until it does./pages/posts/./news/still exists and still serves legacyEntryposts, now on the v2 template. Worth a second opinion on whether/news/should redirect.User.roleon this branch is still a hardcoded"Contributor"stub and there is no badge or org-affiliation source, so the card cannot show a real role, badge or affiliation today. It is wired tou.roleso it improves for free when Story 2443: User Profile Integration – User Roles #2527 lands.Boost.SQLiteas one lexeme, so searching the bareSQLitedoes not match it by title. Library-tagged posts are still reachable through the tag index. There is a test documenting this.Nonein dev, that cache is the first thing to flush.Peer-Testing Guidelines
Setup
jc/2376-post-detail-page) and rundocker compose exec web python manage.py migrate.v3waffle flag to Everyone at http://localhost:8000/admin/. This is also how the logged-out state is tested.docker compose exec web python manage.py convert_news_entries.docker compose exec web python manage.py update_index.Search
Results for "<term>".Filters
News Posts,Blog Posts,Video Posts,Link Posts, andAllshould clear it. Discussions, Achievements and Issues should be visibly disabled.Boost.<Library> Posts. Combine it with a post type: the header shows the post type only, by design.URL state
?type=nonsense,?library=nope,?author=abcand?page=999. Each should degrade quietly to a sensible feed, never a 500.Empty state and user card
Member Since <year>and a Create Post button. In a private window it shows "Create an account" and Sign Up Now.<select>and a visible Filter button appear, and submitting still applies search, pills and library.Screenshots
Self-review Checklist
Frontend