Add search feature has_thumbnails.
Search needs a complete refactor. But until then, let's keep adding to it!
This commit is contained in:
parent
d653673277
commit
f34164bf85
5 changed files with 33 additions and 1 deletions
|
@ -694,7 +694,7 @@ class Photo(ObjectBase):
|
||||||
return_filepath = None
|
return_filepath = None
|
||||||
|
|
||||||
if self.simple_mimetype == 'image':
|
if self.simple_mimetype == 'image':
|
||||||
self.photodb.log.debug('Thumbnailing %s' % self.real_path.absolute_path)
|
self.photodb.log.debug('Thumbnailing %s', self.real_path.absolute_path)
|
||||||
try:
|
try:
|
||||||
image = PIL.Image.open(self.real_path.absolute_path)
|
image = PIL.Image.open(self.real_path.absolute_path)
|
||||||
except (OSError, ValueError):
|
except (OSError, ValueError):
|
||||||
|
@ -728,6 +728,7 @@ class Photo(ObjectBase):
|
||||||
|
|
||||||
elif self.simple_mimetype == 'video' and constants.ffmpeg:
|
elif self.simple_mimetype == 'video' and constants.ffmpeg:
|
||||||
#print('video')
|
#print('video')
|
||||||
|
self.photodb.log.debug('Thumbnailing %s', self.real_path.absolute_path)
|
||||||
probe = constants.ffmpeg.probe(self.real_path.absolute_path)
|
probe = constants.ffmpeg.probe(self.real_path.absolute_path)
|
||||||
try:
|
try:
|
||||||
if probe.video:
|
if probe.video:
|
||||||
|
|
|
@ -348,6 +348,7 @@ class PDBPhotoMixin:
|
||||||
extension_not=None,
|
extension_not=None,
|
||||||
filename=None,
|
filename=None,
|
||||||
has_tags=None,
|
has_tags=None,
|
||||||
|
has_thumbnail=None,
|
||||||
mimetype=None,
|
mimetype=None,
|
||||||
tag_musts=None,
|
tag_musts=None,
|
||||||
tag_mays=None,
|
tag_mays=None,
|
||||||
|
@ -393,6 +394,10 @@ class PDBPhotoMixin:
|
||||||
If False, require that the Photo has no tags.
|
If False, require that the Photo has no tags.
|
||||||
If None, any amount is okay.
|
If None, any amount is okay.
|
||||||
|
|
||||||
|
has_thumbnail:
|
||||||
|
Require a thumbnail?
|
||||||
|
If None, anything is okay.
|
||||||
|
|
||||||
mimetype:
|
mimetype:
|
||||||
A string or list of strings of acceptable mimetypes.
|
A string or list of strings of acceptable mimetypes.
|
||||||
'image', 'video', ...
|
'image', 'video', ...
|
||||||
|
@ -481,6 +486,7 @@ class PDBPhotoMixin:
|
||||||
filename = searchhelpers.normalize_filename(filename)
|
filename = searchhelpers.normalize_filename(filename)
|
||||||
|
|
||||||
limit = searchhelpers.normalize_limit(limit, warning_bag=warning_bag)
|
limit = searchhelpers.normalize_limit(limit, warning_bag=warning_bag)
|
||||||
|
has_thumbnail = searchhelpers.normalize_has_thumbnail(has_thumbnail)
|
||||||
|
|
||||||
offset = searchhelpers.normalize_offset(offset)
|
offset = searchhelpers.normalize_offset(offset)
|
||||||
if offset is None:
|
if offset is None:
|
||||||
|
@ -499,6 +505,7 @@ class PDBPhotoMixin:
|
||||||
orderby = searchhelpers.normalize_orderby(orderby, warning_bag=warning_bag)
|
orderby = searchhelpers.normalize_orderby(orderby, warning_bag=warning_bag)
|
||||||
|
|
||||||
notnulls = set()
|
notnulls = set()
|
||||||
|
yesnulls = set()
|
||||||
if extension or mimetype:
|
if extension or mimetype:
|
||||||
notnulls.add('extension')
|
notnulls.add('extension')
|
||||||
if width or height or ratio or area:
|
if width or height or ratio or area:
|
||||||
|
@ -508,6 +515,11 @@ class PDBPhotoMixin:
|
||||||
if duration:
|
if duration:
|
||||||
notnulls.add('duration')
|
notnulls.add('duration')
|
||||||
|
|
||||||
|
if has_thumbnail is True:
|
||||||
|
notnulls.add('thumbnail')
|
||||||
|
elif has_thumbnail is False:
|
||||||
|
yesnulls.add('thumbnail')
|
||||||
|
|
||||||
if orderby is None:
|
if orderby is None:
|
||||||
giveback_orderby = None
|
giveback_orderby = None
|
||||||
else:
|
else:
|
||||||
|
@ -565,6 +577,7 @@ class PDBPhotoMixin:
|
||||||
'extension_not': extension_not,
|
'extension_not': extension_not,
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
'has_tags': has_tags,
|
'has_tags': has_tags,
|
||||||
|
'has_thumbnail': has_thumbnail,
|
||||||
'mimetype': mimetype,
|
'mimetype': mimetype,
|
||||||
'tag_musts': tag_musts,
|
'tag_musts': tag_musts,
|
||||||
'tag_mays': tag_mays,
|
'tag_mays': tag_mays,
|
||||||
|
@ -596,6 +609,7 @@ class PDBPhotoMixin:
|
||||||
minimums=minimums,
|
minimums=minimums,
|
||||||
mmf_results=mmf_results,
|
mmf_results=mmf_results,
|
||||||
notnulls=notnulls,
|
notnulls=notnulls,
|
||||||
|
yesnulls=yesnulls,
|
||||||
orderby=orderby,
|
orderby=orderby,
|
||||||
)
|
)
|
||||||
print(query[:200])
|
print(query[:200])
|
||||||
|
|
|
@ -18,12 +18,16 @@ def build_query(
|
||||||
minimums=None,
|
minimums=None,
|
||||||
mmf_results=None,
|
mmf_results=None,
|
||||||
notnulls=None,
|
notnulls=None,
|
||||||
|
yesnulls=None,
|
||||||
orderby=None,
|
orderby=None,
|
||||||
):
|
):
|
||||||
|
|
||||||
if notnulls is None:
|
if notnulls is None:
|
||||||
notnulls = set()
|
notnulls = set()
|
||||||
|
|
||||||
|
if yesnulls is None:
|
||||||
|
yesnulls = set()
|
||||||
|
|
||||||
query = ['SELECT * FROM photos']
|
query = ['SELECT * FROM photos']
|
||||||
wheres = set()
|
wheres = set()
|
||||||
|
|
||||||
|
@ -60,6 +64,9 @@ def build_query(
|
||||||
for column in notnulls:
|
for column in notnulls:
|
||||||
wheres.add(column + ' IS NOT NULL')
|
wheres.add(column + ' IS NOT NULL')
|
||||||
|
|
||||||
|
for column in yesnulls:
|
||||||
|
wheres.add(column + ' IS NULL')
|
||||||
|
|
||||||
if wheres:
|
if wheres:
|
||||||
wheres = 'WHERE ' + ' AND '.join(wheres)
|
wheres = 'WHERE ' + ' AND '.join(wheres)
|
||||||
query.append(wheres)
|
query.append(wheres)
|
||||||
|
@ -265,6 +272,9 @@ def normalize_has_tags(has_tags):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def normalize_has_thumbnail(has_thumbnail):
|
||||||
|
return helpers.truthystring(has_thumbnail)
|
||||||
|
|
||||||
def normalize_limit(limit, warning_bag=None):
|
def normalize_limit(limit, warning_bag=None):
|
||||||
if not limit and limit != 0:
|
if not limit and limit != 0:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -235,6 +235,7 @@ def get_search_core():
|
||||||
height = request.args.get('height')
|
height = request.args.get('height')
|
||||||
ratio = request.args.get('ratio')
|
ratio = request.args.get('ratio')
|
||||||
bytes = request.args.get('bytes')
|
bytes = request.args.get('bytes')
|
||||||
|
has_thumbnail = request.args.get('has_thumbnail')
|
||||||
duration = request.args.get('duration')
|
duration = request.args.get('duration')
|
||||||
created = request.args.get('created')
|
created = request.args.get('created')
|
||||||
|
|
||||||
|
@ -253,6 +254,7 @@ def get_search_core():
|
||||||
'extension_not': extension_not,
|
'extension_not': extension_not,
|
||||||
'filename': filename_terms,
|
'filename': filename_terms,
|
||||||
'has_tags': has_tags,
|
'has_tags': has_tags,
|
||||||
|
'has_thumbnail': has_thumbnail,
|
||||||
'mimetype': mimetype,
|
'mimetype': mimetype,
|
||||||
'tag_musts': tag_musts,
|
'tag_musts': tag_musts,
|
||||||
'tag_mays': tag_mays,
|
'tag_mays': tag_mays,
|
||||||
|
|
|
@ -267,6 +267,11 @@ form
|
||||||
<option value="yes"{%if search_kwargs['has_tags'] == True %}selected{%endif%}>Tagged only</option>
|
<option value="yes"{%if search_kwargs['has_tags'] == True %}selected{%endif%}>Tagged only</option>
|
||||||
<option value="no" {%if search_kwargs['has_tags'] == False %}selected{%endif%}>Untagged only</option>
|
<option value="no" {%if search_kwargs['has_tags'] == False %}selected{%endif%}>Untagged only</option>
|
||||||
</select>
|
</select>
|
||||||
|
<select name="has_thumbnail" class="basic_param">
|
||||||
|
<option value="" {%if search_kwargs['has_thumbnail'] == None %}selected{%endif%}>Thumbnail doesn't matter</option>
|
||||||
|
<option value="yes"{%if search_kwargs['has_thumbnail'] == True %}selected{%endif%}>Has thumbnail</option>
|
||||||
|
<option value="no" {%if search_kwargs['has_thumbnail'] == False %}selected{%endif%}>No thumbnail</option>
|
||||||
|
</select>
|
||||||
<select name="view" class="basic_param">
|
<select name="view" class="basic_param">
|
||||||
<option value="grid" {%if search_kwargs['view'] == "grid" %}selected{%endif%}>Grid</option>
|
<option value="grid" {%if search_kwargs['view'] == "grid" %}selected{%endif%}>Grid</option>
|
||||||
<option value="list" {%if search_kwargs['view'] == "list" %}selected{%endif%}>List</option>
|
<option value="list" {%if search_kwargs['view'] == "list" %}selected{%endif%}>List</option>
|
||||||
|
|
Loading…
Reference in a new issue