mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 00:27:41 +01:00
changes from self review
This commit is contained in:
@@ -235,19 +235,18 @@ class DBRomsHandler(DBBaseHandler):
|
||||
return query
|
||||
|
||||
def _filter_by_search_term(self, query: Query, search_term: str):
|
||||
search_terms = search_term.split("|")
|
||||
conditions = []
|
||||
terms = [term.strip() for term in search_term.split("|")]
|
||||
conditions = [
|
||||
condition
|
||||
for term in terms
|
||||
for condition in (
|
||||
Rom.fs_name.ilike(f"%{term}%"),
|
||||
Rom.name.ilike(f"%{term}%"),
|
||||
)
|
||||
if term
|
||||
]
|
||||
|
||||
for term in search_terms:
|
||||
term = term.strip()
|
||||
if term: # Ensure the term is not empty after stripping
|
||||
conditions.append(Rom.fs_name.ilike(f"%{term}%"))
|
||||
conditions.append(Rom.name.ilike(f"%{term}%"))
|
||||
|
||||
if conditions:
|
||||
return query.filter(or_(*conditions))
|
||||
|
||||
return query
|
||||
return query.filter(or_(*conditions))
|
||||
|
||||
def _filter_by_matched(self, query: Query, value: bool) -> Query:
|
||||
"""Filter based on whether the rom is matched to a metadata provider.
|
||||
|
||||
@@ -106,7 +106,6 @@ def test_filter_last_played(rom: Rom, platform: Platform, admin_user: User):
|
||||
|
||||
|
||||
def test_filter_by_search_term_with_multiple_terms(platform: Platform):
|
||||
# Create additional ROMs for testing
|
||||
rom_wwe = db_rom_handler.add_rom(
|
||||
Rom(
|
||||
platform_id=platform.id,
|
||||
|
||||
Reference in New Issue
Block a user