Skip to content

Add featured projects to default sort on Explore Projects page#7230

Open
wtomeo46 wants to merge 1 commit into
hotosm:developfrom
wtomeo46:feature/6704-featured-projects-sort-order
Open

Add featured projects to default sort on Explore Projects page#7230
wtomeo46 wants to merge 1 commit into
hotosm:developfrom
wtomeo46:feature/6704-featured-projects-sort-order

Conversation

@wtomeo46
Copy link
Copy Markdown

What

Implements issue #6704 by adding "featured" projects to the default sort order on the Explore Projects page. When no explicit order_by parameter is supplied, projects are now sorted in the following order:
Urgent → Featured → High → Medium → Low

Why

As described in #6704, the Explore Projects page currently defaults to sorting by priority, with older projects appearing first within each priority group. This means the front page is often dominated by outdated projects and beginner-friendly projects are hard to find. The "featured" flag had no effect on the default sort. This PR makes featured projects discoverable in the default view by placing them in their own prioritized tier.

How

Two small changes in backend/services/project_search_service.py:

  1. SELECT: Added p.featured to the project search query to be available for ordering.
  2. ORDER BY: Replaced the previously empty default order_by_clause with a CASE expression that orders the five tiers. The existing logic that overrides order_by_clause when search_dto.order_by is provided is preserved.

Testing

Added test_default_sort_order_places_featured_between_urgent_and_high in tests/api/unit/services/test_project_search_service.py. The test initializes 4 projects covering each tier (urgent, featured-high, plain-high, medium) and asserts that search service returns them in the expected order when no order_by is supplied.

To run:
'uv run python -m pytest tests/api/unit/services/test_project_search_service.py -v'

All 4 tests in that file pass locally.

Featured projects now appear between Urgent and High priority in the
default sort order when no explicit order_by is specified, implementing
the tier ordering: Urgent > Featured > High > Medium > Low.

Adds p.featured to the SELECT clause and a default ORDER BY clause that
encodes the new sort tiers via a CASE expression. The existing override
behavior for explicit order_by parameters is preserved.

Includes a unit test verifying the new default sort order.

Closes hotosm#6704
@sonarqubecloud
Copy link
Copy Markdown

@SColchester
Copy link
Copy Markdown

Great, how would the featured attribute be added to projects? Just by Tasking Manager admins?

@wtomeo46
Copy link
Copy Markdown
Author

Yes, as already set, only admin users can set the featured attribute through the project edit page as access is gated by UserRole.ADMIN.

@SColchester
Copy link
Copy Markdown

Fantastic @wtomeo46! Great

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.

2 participants