Skip to content

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Oct 9, 2025

Add a page search endpoint to expose Page.objects.search via the REST API with pagination, and include a corresponding test to verify the search response structure.

New Features:

  • Introduce PageSearchView subclassing PageListView to handle search queries and filter PageContent based on the search term
  • Register the new page-search URL pattern under "/page_search/"

Tests:

  • Add test_page_search to verify the search endpoint returns the correct status, pagination attributes, and result count

Fixes #60 by adding an endpoint for Page.objects.search method.

Test added (but fails due to bug in django-cms): The Page.objects.search method is broken for django CMS 4+. Fix is here: django-cms/django-cms#8355

Copy link
Contributor

sourcery-ai bot commented Oct 9, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces a new search endpoint by adding a PageSearchView that invokes Page.objects.search and filters the results, and exposes it via a dedicated URL route.

Sequence diagram for the new page search endpoint

sequenceDiagram
actor User
participant API as "PageSearchView"
participant Page as "Page.objects"
participant PageContent as "PageContent.objects"
User->>API: GET /<language>/search_pages/?q=term
API->>Page: search(term, language, current_site_only=False)
Page-->>API: queryset of matching pages
API->>PageContent: filter(page__in=qs).distinct()
PageContent-->>API: queryset of matching PageContent
API-->>User: Response with search results
Loading

Class diagram for the new PageSearchView

classDiagram
class PageListView
class PageSearchView {
  +get(request, language)
  +get_queryset()
  -search_term
  -language
}
PageSearchView --|> PageListView
Loading

File-Level Changes

Change Details Files
Add PageSearchView to handle page search requests
  • Inherit from PageListView and override get() to extract query and language parameters
  • Implement get_queryset() to call Page.objects.search with language and site filters
  • Filter results through PageContent.objects and ensure distinct pages are returned
djangocms_rest/views.py
Register the new search endpoint in URL configuration
  • Add a path for 'slug:language/search_pages/'
  • Map the route to PageSearchView.as_view()
  • Assign the route name 'page-search'
djangocms_rest/urls.py

Assessment against linked issues

Issue Objective Addressed Explanation
#60 Implement a search endpoint to allow fetching pages by search terms (full-text search, ideally including plugin content).
#60 Follow the Django CMS implementation pattern for the search endpoint.
#60 Make the search endpoint extensible to include custom apps and allow 3rd-party implementations (e.g., Elastic Search, Algolia), ideally with preset configuration or instructions for fast implementation. The PR only adds a basic search endpoint for pages using the built-in Page.objects.search method. It does not include extensibility for custom apps, 3rd-party integrations, or preset configuration/instructions for fast implementation.

Possibly linked issues

  • add search endpoint #60: The PR adds a new search page endpoint to djangocms-rest, which directly implements the search functionality requested in issue 60.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 30.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.01%. Comparing base (1a5d292) to head (381497f).

Files with missing lines Patch % Lines
djangocms_rest/views.py 30.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #64      +/-   ##
==========================================
- Coverage   91.75%   91.01%   -0.74%     
==========================================
  Files          18       18              
  Lines         825      835      +10     
  Branches       89       90       +1     
==========================================
+ Hits          757      760       +3     
- Misses         42       49       +7     
  Partials       26       26              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider renaming the "search_pages" endpoint to simply "search" to align with the existing URL conventions and keep things consistent.
  • Add explicit handling for an empty q parameter (e.g. return an empty result or validation error) to avoid unintentionally returning all pages when no search term is provided.
  • Rather than overriding the get method, you might integrate the search logic into a filter backend or extend the existing get_queryset flow to preserve pagination and DRF conventions without duplicating request handling.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider renaming the "search_pages" endpoint to simply "search" to align with the existing URL conventions and keep things consistent.
- Add explicit handling for an empty `q` parameter (e.g. return an empty result or validation error) to avoid unintentionally returning all pages when no search term is provided.
- Rather than overriding the `get` method, you might integrate the search logic into a filter backend or extend the existing `get_queryset` flow to preserve pagination and DRF conventions without duplicating request handling.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fsbraun fsbraun requested a review from metaforx October 9, 2025 16:20
@fsbraun fsbraun changed the title feat: Add search page endpoint feat: Add page search endpoint Oct 9, 2025
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.

add search endpoint

1 participant