mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-01-31 23:29:10 +00:00
feat: make path search use globs (#582)
* feat: make path search use globs * fix: specify types in path search * chore: format with ruff
This commit is contained in:
@@ -438,7 +438,8 @@ class Library:
|
||||
)
|
||||
)
|
||||
elif search.path:
|
||||
statement = statement.where(Entry.path.ilike(f"%{search.path}%"))
|
||||
search_str = str(search.path).replace("*", "%")
|
||||
statement = statement.where(Entry.path.ilike(search_str))
|
||||
elif search.filetype:
|
||||
statement = statement.where(Entry.suffix.ilike(f"{search.filetype}"))
|
||||
elif search.mediatype:
|
||||
|
||||
@@ -94,7 +94,7 @@ def test_library_state_update(qt_driver):
|
||||
assert list(entry.tags)[0].name == "foo"
|
||||
|
||||
# When state property is changed, previous one is overwritten
|
||||
state = FilterState(path="bar.md")
|
||||
state = FilterState(path="*bar.md")
|
||||
qt_driver.filter_items(state)
|
||||
assert len(qt_driver.frame_content) == 1
|
||||
entry = qt_driver.frame_content[0]
|
||||
|
||||
@@ -3,7 +3,7 @@ from tempfile import TemporaryDirectory
|
||||
|
||||
import pytest
|
||||
from src.core.enums import DefaultEnum, LibraryPrefs
|
||||
from src.core.library.alchemy import Entry
|
||||
from src.core.library.alchemy import Entry, Library
|
||||
from src.core.library.alchemy.enums import FilterState
|
||||
from src.core.library.alchemy.fields import TextField, _FieldID
|
||||
|
||||
@@ -403,6 +403,24 @@ def test_library_prefs_multiple_identical_vals():
|
||||
assert TestPrefs.BAR.value
|
||||
|
||||
|
||||
def test_path_search_glob_after(library: Library):
|
||||
results = library.search_library(FilterState(path="foo*"))
|
||||
assert results.total_count == 1
|
||||
assert len(results.items) == 1
|
||||
|
||||
|
||||
def test_path_search_glob_in_front(library: Library):
|
||||
results = library.search_library(FilterState(path="*bar.md"))
|
||||
assert results.total_count == 1
|
||||
assert len(results.items) == 1
|
||||
|
||||
|
||||
def test_path_search_glob_both_sides(library: Library):
|
||||
results = library.search_library(FilterState(path="*one/two*"))
|
||||
assert results.total_count == 1
|
||||
assert len(results.items) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(["filetype", "num_of_filetype"], [("md", 1), ("txt", 1), ("png", 0)])
|
||||
def test_filetype_search(library, filetype, num_of_filetype):
|
||||
results = library.search_library(FilterState(filetype=filetype))
|
||||
|
||||
Reference in New Issue
Block a user