Add Album.has_any_photo and has_any_subalbum_photo.

This commit is contained in:
voussoir 2018-04-15 02:41:24 -07:00
parent 0ee07023a1
commit f77ab51b14
2 changed files with 15 additions and 1 deletions

View file

@ -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)

View file

@ -103,7 +103,7 @@ p
<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 %}