file format filter in search

This commit is contained in:
dave 2021-09-27 21:39:43 -07:00
parent ee08ba8100
commit ca4a46fcc3
2 changed files with 19 additions and 2 deletions

View File

@ -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,

View File

@ -65,6 +65,14 @@
<div class="pure-u-1-5">
<p>Options</p>
<label><input type="checkbox" name="untagged" value="1"{% if selecting_untagged %} checked="checked"{% endif %} /> Untagged</label>
<p>Formats</p>
<select multiple name="include_formats" style="height:140px;width:75%;">
{% for format_name in ftypes.keys() %}
<option value="{{ format_name }}"{% if format_name in include_formats %} selected{% endif %}>{{ format_name }}</option>
{% endfor %}
</select>
</div>
</div>