From ca4a46fcc3d6fcecbaadee776f26e7aa15375fa8 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 27 Sep 2021 21:39:43 -0700 Subject: [PATCH] file format filter in search --- photoapp/daemon.py | 13 +++++++++++-- templates/search.html | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/photoapp/daemon.py b/photoapp/daemon.py index 5106a8f..a2a3196 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -8,7 +8,7 @@ from urllib.parse import urlparse from datetime import datetime, timedelta from photoapp.thumbtool import ThumbGenerator from photoapp.types import APPROOT, Photo, PhotoSet, Tag, TagItem, PhotoStatus, User, mime2ext, \ - regular_mimes, video_mimes + regular_mimes, video_mimes, ftypes from photoapp.dbsession import DatabaseSession from photoapp.common import pwhash from photoapp.api import PhotosApi, LibraryManager @@ -67,7 +67,8 @@ class PhotosWeb(object): "all_tags": tagq, "path": cherrypy.request.path_info, "auth": auth(), - "PhotoStatus": PhotoStatus + "PhotoStatus": PhotoStatus, + "ftypes": ftypes } return ret @@ -441,6 +442,7 @@ class SearchView(object): include_tags=None, exclude_tags=None, untagged=False, + include_formats=None, before=None, after=None, set_before=None, @@ -464,6 +466,7 @@ class SearchView(object): exclude_tags = cherryparam(exclude_tags) add_tag = cherryparam(add_tag) remove_tag = cherryparam(remove_tag) + include_formats = cherryparam(include_formats) or list(ftypes.keys()) untagged = untagged in frozenset([True, 1, "1", "yes"]) @@ -518,6 +521,11 @@ class SearchView(object): base = base \ .filter(PhotoSet.id.in_(db.query(Photo.set_id).filter(Photo.fname.like("%{}%".format(keywords_filename))))) + # TODO there are two filters that use a Photo subquery. They could probably be combined. + allowed_mimes = set().union(*[mime["mimes"] for ext, mime in ftypes.items() if ext in include_formats]) + base = base.filter(PhotoSet.id.in_( + db.query(Photo.set_id).filter(Photo.format.in_(allowed_mimes)))) + base = base \ .order_by(PhotoSet.date.desc()) @@ -570,6 +578,7 @@ class SearchView(object): include_tags=include_tags, exclude_tags=exclude_tags, selecting_untagged=untagged, + include_formats=include_formats, images=[i for i in images], total_sets=total_sets, page=page, diff --git a/templates/search.html b/templates/search.html index 9437228..bb88018 100644 --- a/templates/search.html +++ b/templates/search.html @@ -65,6 +65,14 @@

Options

+ +

Formats

+ +