From f34164bf85453349f1fbac5f243132734d0438ee Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 24 Feb 2018 23:06:25 -0800 Subject: [PATCH] Add search feature has_thumbnails. Search needs a complete refactor. But until then, let's keep adding to it! --- etiquette/objects.py | 3 ++- etiquette/photodb.py | 14 ++++++++++++++ etiquette/searchhelpers.py | 10 ++++++++++ .../etiquette_flask/endpoints/photo_endpoints.py | 2 ++ frontends/etiquette_flask/templates/search.html | 5 +++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index d7f930b..0eb0b19 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -694,7 +694,7 @@ class Photo(ObjectBase): return_filepath = None 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: image = PIL.Image.open(self.real_path.absolute_path) except (OSError, ValueError): @@ -728,6 +728,7 @@ class Photo(ObjectBase): elif self.simple_mimetype == 'video' and constants.ffmpeg: #print('video') + self.photodb.log.debug('Thumbnailing %s', self.real_path.absolute_path) probe = constants.ffmpeg.probe(self.real_path.absolute_path) try: if probe.video: diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 9cffd43..6e5884e 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -348,6 +348,7 @@ class PDBPhotoMixin: extension_not=None, filename=None, has_tags=None, + has_thumbnail=None, mimetype=None, tag_musts=None, tag_mays=None, @@ -393,6 +394,10 @@ class PDBPhotoMixin: If False, require that the Photo has no tags. If None, any amount is okay. + has_thumbnail: + Require a thumbnail? + If None, anything is okay. + mimetype: A string or list of strings of acceptable mimetypes. 'image', 'video', ... @@ -481,6 +486,7 @@ class PDBPhotoMixin: filename = searchhelpers.normalize_filename(filename) limit = searchhelpers.normalize_limit(limit, warning_bag=warning_bag) + has_thumbnail = searchhelpers.normalize_has_thumbnail(has_thumbnail) offset = searchhelpers.normalize_offset(offset) if offset is None: @@ -499,6 +505,7 @@ class PDBPhotoMixin: orderby = searchhelpers.normalize_orderby(orderby, warning_bag=warning_bag) notnulls = set() + yesnulls = set() if extension or mimetype: notnulls.add('extension') if width or height or ratio or area: @@ -508,6 +515,11 @@ class PDBPhotoMixin: if duration: notnulls.add('duration') + if has_thumbnail is True: + notnulls.add('thumbnail') + elif has_thumbnail is False: + yesnulls.add('thumbnail') + if orderby is None: giveback_orderby = None else: @@ -565,6 +577,7 @@ class PDBPhotoMixin: 'extension_not': extension_not, 'filename': filename, 'has_tags': has_tags, + 'has_thumbnail': has_thumbnail, 'mimetype': mimetype, 'tag_musts': tag_musts, 'tag_mays': tag_mays, @@ -596,6 +609,7 @@ class PDBPhotoMixin: minimums=minimums, mmf_results=mmf_results, notnulls=notnulls, + yesnulls=yesnulls, orderby=orderby, ) print(query[:200]) diff --git a/etiquette/searchhelpers.py b/etiquette/searchhelpers.py index 3dbcb74..9e34448 100644 --- a/etiquette/searchhelpers.py +++ b/etiquette/searchhelpers.py @@ -18,12 +18,16 @@ def build_query( minimums=None, mmf_results=None, notnulls=None, + yesnulls=None, orderby=None, ): if notnulls is None: notnulls = set() + if yesnulls is None: + yesnulls = set() + query = ['SELECT * FROM photos'] wheres = set() @@ -60,6 +64,9 @@ def build_query( for column in notnulls: wheres.add(column + ' IS NOT NULL') + for column in yesnulls: + wheres.add(column + ' IS NULL') + if wheres: wheres = 'WHERE ' + ' AND '.join(wheres) query.append(wheres) @@ -265,6 +272,9 @@ def normalize_has_tags(has_tags): return None +def normalize_has_thumbnail(has_thumbnail): + return helpers.truthystring(has_thumbnail) + def normalize_limit(limit, warning_bag=None): if not limit and limit != 0: return None diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py index 599c252..5bc4740 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py @@ -235,6 +235,7 @@ def get_search_core(): height = request.args.get('height') ratio = request.args.get('ratio') bytes = request.args.get('bytes') + has_thumbnail = request.args.get('has_thumbnail') duration = request.args.get('duration') created = request.args.get('created') @@ -253,6 +254,7 @@ def get_search_core(): 'extension_not': extension_not, 'filename': filename_terms, 'has_tags': has_tags, + 'has_thumbnail': has_thumbnail, 'mimetype': mimetype, 'tag_musts': tag_musts, 'tag_mays': tag_mays, diff --git a/frontends/etiquette_flask/templates/search.html b/frontends/etiquette_flask/templates/search.html index 4292f73..20d1702 100644 --- a/frontends/etiquette_flask/templates/search.html +++ b/frontends/etiquette_flask/templates/search.html @@ -267,6 +267,11 @@ form +