file format filter in search
This commit is contained in:
parent
ee08ba8100
commit
ca4a46fcc3
|
@ -8,7 +8,7 @@ from urllib.parse import urlparse
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from photoapp.thumbtool import ThumbGenerator
|
from photoapp.thumbtool import ThumbGenerator
|
||||||
from photoapp.types import APPROOT, Photo, PhotoSet, Tag, TagItem, PhotoStatus, User, mime2ext, \
|
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.dbsession import DatabaseSession
|
||||||
from photoapp.common import pwhash
|
from photoapp.common import pwhash
|
||||||
from photoapp.api import PhotosApi, LibraryManager
|
from photoapp.api import PhotosApi, LibraryManager
|
||||||
|
@ -67,7 +67,8 @@ class PhotosWeb(object):
|
||||||
"all_tags": tagq,
|
"all_tags": tagq,
|
||||||
"path": cherrypy.request.path_info,
|
"path": cherrypy.request.path_info,
|
||||||
"auth": auth(),
|
"auth": auth(),
|
||||||
"PhotoStatus": PhotoStatus
|
"PhotoStatus": PhotoStatus,
|
||||||
|
"ftypes": ftypes
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -441,6 +442,7 @@ class SearchView(object):
|
||||||
include_tags=None,
|
include_tags=None,
|
||||||
exclude_tags=None,
|
exclude_tags=None,
|
||||||
untagged=False,
|
untagged=False,
|
||||||
|
include_formats=None,
|
||||||
before=None,
|
before=None,
|
||||||
after=None,
|
after=None,
|
||||||
set_before=None,
|
set_before=None,
|
||||||
|
@ -464,6 +466,7 @@ class SearchView(object):
|
||||||
exclude_tags = cherryparam(exclude_tags)
|
exclude_tags = cherryparam(exclude_tags)
|
||||||
add_tag = cherryparam(add_tag)
|
add_tag = cherryparam(add_tag)
|
||||||
remove_tag = cherryparam(remove_tag)
|
remove_tag = cherryparam(remove_tag)
|
||||||
|
include_formats = cherryparam(include_formats) or list(ftypes.keys())
|
||||||
|
|
||||||
untagged = untagged in frozenset([True, 1, "1", "yes"])
|
untagged = untagged in frozenset([True, 1, "1", "yes"])
|
||||||
|
|
||||||
|
@ -518,6 +521,11 @@ class SearchView(object):
|
||||||
base = base \
|
base = base \
|
||||||
.filter(PhotoSet.id.in_(db.query(Photo.set_id).filter(Photo.fname.like("%{}%".format(keywords_filename)))))
|
.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 \
|
base = base \
|
||||||
.order_by(PhotoSet.date.desc())
|
.order_by(PhotoSet.date.desc())
|
||||||
|
|
||||||
|
@ -570,6 +578,7 @@ class SearchView(object):
|
||||||
include_tags=include_tags,
|
include_tags=include_tags,
|
||||||
exclude_tags=exclude_tags,
|
exclude_tags=exclude_tags,
|
||||||
selecting_untagged=untagged,
|
selecting_untagged=untagged,
|
||||||
|
include_formats=include_formats,
|
||||||
images=[i for i in images],
|
images=[i for i in images],
|
||||||
total_sets=total_sets,
|
total_sets=total_sets,
|
||||||
page=page,
|
page=page,
|
||||||
|
|
|
@ -65,6 +65,14 @@
|
||||||
<div class="pure-u-1-5">
|
<div class="pure-u-1-5">
|
||||||
<p>Options</p>
|
<p>Options</p>
|
||||||
<label><input type="checkbox" name="untagged" value="1"{% if selecting_untagged %} checked="checked"{% endif %} /> Untagged</label>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue