Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions games/migrations/0088_install_unaccent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 5.2.11 on 2026-11-23 08:38

from django.db import migrations
from django.contrib.postgres.operations import UnaccentExtension


class Migration(migrations.Migration):

dependencies = [
('games', '0087_spamdomain_gamesubmission_ip_address'),
]

operations = [
UnaccentExtension(),
]
52 changes: 52 additions & 0 deletions games/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class TestGameViews(TestCase):

def setUp(self):
factories.CompanyFactory(name="Team 17", slug="team-17")
factories.GameFactory(name="Pokémon Red", slug="pokemon-red")
factories.GameFactory(
name="Counter-Strike: Global Offensive", slug="counter-strike-global-offensive"
)
factories.GameFactory(
name="S.T.A.L.K.E.R.: Shadow of Chernobyl", slug="stalker-shadow-of-chernobyl"
)
factories.GameFactory(name="Baldur's Gate", slug="baldurs-gate")
factories.GameFactory(
name="Warhammer 40,000: Dawn of War", slug="warhammer-40000-dawn-of-war"
)

def test_can_get_game_list(self):
"""Can get the basic game list"""
Expand Down Expand Up @@ -128,6 +139,47 @@ def test_can_receive_garbage_pagination_by(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

def test_can_search_for_games_with_unaccented_characters(self):
response = self.client.get(reverse("game_list"), {"q": "pokemon"})
self.assertEqual(response.status_code, 200)
self.assertIn("pokemon-red", [game.slug for game in response.context["games"]])

def test_can_search_for_games_with_special_characters(self):
test_cases = [
("Counter Strike", "counter-strike-global-offensive"),
("STALKER", "stalker-shadow-of-chernobyl"),
("Baldurs Gate", "baldurs-gate"),
("Warhammer 40000 Dawn of War", "warhammer-40000-dawn-of-war"),
]

for search_term, expected_slug in test_cases:
with self.subTest(search_term=search_term, expected_slug=expected_slug):
response = self.client.get(reverse("game_list"), {"q": search_term})
self.assertEqual(response.status_code, 200)
self.assertIn(expected_slug, [game.slug for game in response.context["games"]])

def test_punctuation_only_search_does_not_match_every_game(self):
"""slugify(non-alphanumeric) returns an empty string, which would match every game"""
test_cases = ["!!!", "ポケモン"]
for search_term in test_cases:
with self.subTest(search_term=search_term):
response = self.client.get(reverse("game_list"), {"q": search_term})
self.assertEqual(response.status_code, 200)
self.assertFalse(response.context["games"])

def test_empty_slug_search_term_fallback_to_name_search(self):
response = self.client.get(reverse("game_list"), {"q": ":"})
self.assertEqual(response.status_code, 200)
self.assertIn(
"counter-strike-global-offensive", [game.slug for game in response.context["games"]]
)
self.assertIn(
"stalker-shadow-of-chernobyl", [game.slug for game in response.context["games"]]
)
self.assertIn(
"warhammer-40000-dawn-of-war", [game.slug for game in response.context["games"]]
)


class TestGameSubmissionView(TestCase):
"""Submitting a game records where it came from"""
Expand Down
9 changes: 7 additions & 2 deletions games/views/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from sorl.thumbnail import get_thumbnail

from accounts.decorators import user_confirmed_required
from common.util import slugify
from emails.messages import send_email
from games import models
from games.forms import (
Expand Down Expand Up @@ -133,9 +134,13 @@ def get_filtered_queryset(self, queryset):
queryset = queryset.filter(installers__content__icontains=self.q_params["q"])
else:
search_query = self.q_params["q"]
queryset = queryset.filter(
Q(name__icontains=search_query) | Q(aliases__name__icontains=search_query)
slug = slugify(search_query)
search_filter = Q(name__unaccent__icontains=search_query) | Q(
aliases__name__unaccent__icontains=search_query
)
if slug:
search_filter = search_filter | Q(slug__icontains=slug)
queryset = queryset.filter(search_filter)
if self.q_params["platforms"]:
queryset = queryset.filter(platforms__pk__in=self.q_params["platforms"])
if self.q_params["genres"]:
Expand Down
1 change: 1 addition & 0 deletions lutrisweb/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def media_directory(path):
"django.contrib.humanize",
"django.contrib.admin",
"django.contrib.admindocs",
"django.contrib.postgres",
"sorl.thumbnail",
"rest_framework",
"rest_framework.authtoken",
Expand Down