From: Christian Heller Date: Tue, 10 Dec 2024 23:38:43 +0000 (+0100) Subject: Treat tag filter input fields as OR of comma-delimited terms. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/conditions?a=commitdiff_plain;h=33e8353b4ef532e45b7f3845b6431871b798a069;p=ytplom Treat tag filter input fields as OR of comma-delimited terms. --- diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 90c5e3e..e3d3728 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -305,11 +305,18 @@ class VideoFile(DbData): show_absent: bool = False ) -> list[Self]: """Return cls.get_all matching provided filter criteria.""" - return [f for f in cls.get_all(conn) + filtered_before_tags = [ + f for f in cls.get_all(conn) if str(filter_path).lower() in str(f.rel_path).lower() - and ([t for t in f.tags if str(filter_tags).lower() in t] - or not filter_tags) and (show_absent or f.present)] + if filter_tags: + tags_or = filter_tags.split(',') + filtered_after_tags = set() + for f in filtered_before_tags: + for t in [t for t in tags_or if t in f.tags]: + filtered_after_tags.add(f) + return list(filtered_after_tags) + return filtered_before_tags def unused_tags(self, conn: BaseDbConn) -> set[Tag]: """Return tags used among other VideoFiles, not in self."""