Add get_albums_within_directory.
This commit is contained in:
		
							parent
							
								
									017633331b
								
							
						
					
					
						commit
						8e964e2888
					
				
					 1 changed files with 17 additions and 0 deletions
				
			
		|  | @ -57,6 +57,23 @@ class PDBAlbumMixin: | ||||||
|     def get_albums_by_sql(self, query, bindings=None): |     def get_albums_by_sql(self, query, bindings=None): | ||||||
|         return self.get_things_by_sql('album', query, bindings) |         return self.get_things_by_sql('album', query, bindings) | ||||||
| 
 | 
 | ||||||
|  |     def get_albums_within_directory(self, directory): | ||||||
|  |         # This function is something of a stopgap measure since `search` only | ||||||
|  |         # searches for photos and then yields their containing albums. Thus it | ||||||
|  |         # is not possible for search to find albums that contain no photos. | ||||||
|  |         # I'd like to find a better solution than this separate method. | ||||||
|  |         directory = pathclass.Path(directory) | ||||||
|  |         directory.assert_is_directory() | ||||||
|  |         pattern = directory.absolute_path.rstrip(os.sep) | ||||||
|  |         pattern = f'{pattern}{os.sep}%' | ||||||
|  |         album_rows = self.sql_select( | ||||||
|  |             'SELECT DISTINCT albumid FROM album_associated_directories WHERE directory LIKE ?', | ||||||
|  |             [pattern] | ||||||
|  |         ) | ||||||
|  |         album_ids = (album_id for (album_id,) in album_rows) | ||||||
|  |         albums = self.get_albums_by_id(album_ids) | ||||||
|  |         return albums | ||||||
|  | 
 | ||||||
|     def get_root_albums(self): |     def get_root_albums(self): | ||||||
|         ''' |         ''' | ||||||
|         Yield Albums that have no parent. |         Yield Albums that have no parent. | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue