diff --git a/viewer/views.py b/viewer/views.py index dae28bf..27ef1e9 100644 --- a/viewer/views.py +++ b/viewer/views.py @@ -34,11 +34,12 @@ def do_recursive_search(start_path, query): """ # Get all sub-dirs and images that match the query. - subdirs = sorted([i.absolute() for i in start_path.iterdir() if i.is_dir() and query.lower() in i.name.lower()]) - images = sorted([i for i in start_path.iterdir() if i.is_file() and filetype.is_image(str(i)) and query.lower() in i.name.lower()]) + all_subdirs = sorted([i for i in start_path.iterdir() if i.is_dir()]) + subdirs = sorted([i for i in all_subdirs if query.lower() in i.name.lower()]) + images = sorted([i for i in start_path.iterdir() if i.is_file() and query.lower() in i.name.lower()]) # For all sub-directories, regardless of the query. - for subdir in sorted([i for i in start_path.iterdir() if i.is_dir()]): + for subdir in all_subdirs: # Do a recursive search. rec_subdirs, rec_images = do_recursive_search(subdir, query.lower()) @@ -94,6 +95,9 @@ def gallery_view(request, path = None): # If there is a search query then search the current directory recursively. subdirs, images = do_recursive_search(full_path, search) + # Only keep image files. + images = [image for image in images if filetype.is_image(str(image))] + # For every sub-directory found, prepare it's name and path for rendering. subdir_data = [] for subdir in subdirs: