diff --git a/etiquette/objects.py b/etiquette/objects.py index c0ce0ee..f4932f6 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -451,6 +451,20 @@ class Album(ObjectBase, GroupableMixin): photos = sorted(photos, key=lambda x: x.basename.lower()) return photos + def has_any_photo(self, recurse=False): + row = self.photodb.sql_select_one( + 'SELECT photoid FROM album_photo_rel WHERE albumid == ? LIMIT 1', + [self.id] + ) + if row is not None: + return True + if recurse: + return self.has_any_subalbum_photo() + return False + + def has_any_subalbum_photo(self): + return any(child.has_any_photo(recurse=True) for child in self.get_children()) + def has_photo(self, photo): if not isinstance(photo, Photo): raise TypeError('`photo` must be of type %s' % Photo) diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index 5f9e112..50fff48 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -103,7 +103,7 @@ p

{% set has_local_photos = photos|length > 0 %} - {% set has_child_photos = album.sum_photos() > photos|length %} + {% set has_child_photos = album.has_any_subalbum_photo() %} {% if has_local_photos or has_child_photos %} Download: {% if has_local_photos %}