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 | ||||
| 
 | ||||
|         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: | ||||
|  |  | |||
|  | @ -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]) | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -267,6 +267,11 @@ form | |||
|                 <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> | ||||
|             </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"> | ||||
|                 <option value="grid" {%if search_kwargs['view'] == "grid" %}selected{%endif%}>Grid</option> | ||||
|                 <option value="list" {%if search_kwargs['view'] == "list" %}selected{%endif%}>List</option> | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue