Add Album.sum_children.
This commit is contained in:
		
							parent
							
								
									75c6c11b0d
								
							
						
					
					
						commit
						484e3ae1ee
					
				
					 2 changed files with 21 additions and 5 deletions
				
			
		|  | @ -562,13 +562,13 @@ class Album(ObjectBase, GroupableMixin): | ||||||
|             self._remove_photo(photo) |             self._remove_photo(photo) | ||||||
| 
 | 
 | ||||||
|     def sum_bytes(self, recurse=True): |     def sum_bytes(self, recurse=True): | ||||||
|         query = ''' |         query = stringtools.collapse_whitespace(''' | ||||||
|         SELECT SUM(bytes) FROM photos |         SELECT SUM(bytes) FROM photos | ||||||
|         WHERE photos.id IN ( |         WHERE photos.id IN ( | ||||||
|             SELECT photoid FROM album_photo_rel WHERE |             SELECT photoid FROM album_photo_rel WHERE | ||||||
|             albumid IN {albumids} |             albumid IN {albumids} | ||||||
|         ) |         ) | ||||||
|         ''' |         ''') | ||||||
|         if recurse: |         if recurse: | ||||||
|             albumids = [child.id for child in self.walk_children()] |             albumids = [child.id for child in self.walk_children()] | ||||||
|         else: |         else: | ||||||
|  | @ -579,17 +579,33 @@ class Album(ObjectBase, GroupableMixin): | ||||||
|         total = self.photodb.sql_select_one(query)[0] |         total = self.photodb.sql_select_one(query)[0] | ||||||
|         return total |         return total | ||||||
| 
 | 
 | ||||||
|  |     def sum_children(self, recurse=True): | ||||||
|  |         if recurse: | ||||||
|  |             walker = self.walk_children() | ||||||
|  |             # First yield is itself. | ||||||
|  |             next(walker) | ||||||
|  |             return sum(1 for child in walker) | ||||||
|  | 
 | ||||||
|  |         query = stringtools.collapse_whitespace(''' | ||||||
|  |         SELECT COUNT(memberid) | ||||||
|  |         FROM album_group_rel | ||||||
|  |         WHERE parentid == ? | ||||||
|  |         ''') | ||||||
|  |         bindings = [self.id] | ||||||
|  |         total = self.photodb.sql_select_one(query, bindings)[0] | ||||||
|  |         return total | ||||||
|  | 
 | ||||||
|     def sum_photos(self, recurse=True): |     def sum_photos(self, recurse=True): | ||||||
|         ''' |         ''' | ||||||
|         If all you need is the number of photos in the album, this method is |         If all you need is the number of photos in the album, this method is | ||||||
|         preferable to len(album.get_photos()) because it performs the counting |         preferable to len(album.get_photos()) because it performs the counting | ||||||
|         in the database instead of creating the Photo objects. |         in the database instead of creating the Photo objects. | ||||||
|         ''' |         ''' | ||||||
|         query = ''' |         query = stringtools.collapse_whitespace(''' | ||||||
|         SELECT COUNT(photoid) |         SELECT COUNT(photoid) | ||||||
|         FROM album_photo_rel |         FROM album_photo_rel | ||||||
|         WHERE albumid IN {albumids} |         WHERE albumid IN {albumids} | ||||||
|         ''' |         ''') | ||||||
|         if recurse: |         if recurse: | ||||||
|             albumids = [child.id for child in self.walk_children()] |             albumids = [child.id for child in self.walk_children()] | ||||||
|         else: |         else: | ||||||
|  |  | ||||||
|  | @ -47,7 +47,7 @@ draggable=true | ||||||
|     <div class="album_card_metadata"> |     <div class="album_card_metadata"> | ||||||
|         {% if album == "root" %} |         {% if album == "root" %} | ||||||
|         {% else %} |         {% else %} | ||||||
|         {% set child_count = album.get_children()|length %} |         {% set child_count = album.sum_children(recurse=False) %} | ||||||
|         {% set photo_count = album.sum_photos(recurse=False) %} |         {% set photo_count = album.sum_photos(recurse=False) %} | ||||||
|         <span class="album_card_child_count" title="{{child_count}} child albums">{{child_count}}</span> |         <span class="album_card_child_count" title="{{child_count}} child albums">{{child_count}}</span> | ||||||
|         {{-' | '-}} |         {{-' | '-}} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue