Rename Album.photos -> get_photos.
This commit is contained in:
parent
6574450ad1
commit
ac9d7ede22
5 changed files with 19 additions and 19 deletions
|
@ -47,7 +47,7 @@ def album_zip_filenames(album, recursive=True):
|
||||||
arcnames = {}
|
arcnames = {}
|
||||||
directories = album_zip_directories(album, recursive=recursive)
|
directories = album_zip_directories(album, recursive=recursive)
|
||||||
for (album, directory) in directories.items():
|
for (album, directory) in directories.items():
|
||||||
photos = album.photos()
|
photos = album.get_photos()
|
||||||
for photo in photos:
|
for photo in photos:
|
||||||
if photo.real_filepath in arcnames:
|
if photo.real_filepath in arcnames:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -10,7 +10,7 @@ def album(a, minimal=False):
|
||||||
'title': a.title,
|
'title': a.title,
|
||||||
}
|
}
|
||||||
if not minimal:
|
if not minimal:
|
||||||
j['photos'] = [photo(p) for p in a.photos()]
|
j['photos'] = [photo(p) for p in a.get_photos()]
|
||||||
parent = a.get_parent()
|
parent = a.get_parent()
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
j['parent'] = album(parent, minimal=True)
|
j['parent'] = album(parent, minimal=True)
|
||||||
|
|
|
@ -326,7 +326,7 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
if nested_children:
|
if nested_children:
|
||||||
photos = self.walk_photos()
|
photos = self.walk_photos()
|
||||||
else:
|
else:
|
||||||
photos = self.photos()
|
photos = self.get_photos()
|
||||||
|
|
||||||
for photo in photos:
|
for photo in photos:
|
||||||
photo.add_tag(tag, commit=False)
|
photo.add_tag(tag, commit=False)
|
||||||
|
@ -392,6 +392,17 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
self.photodb.log.debug('Committing - edit album')
|
self.photodb.log.debug('Committing - edit album')
|
||||||
self.photodb.commit()
|
self.photodb.commit()
|
||||||
|
|
||||||
|
def get_photos(self):
|
||||||
|
photos = []
|
||||||
|
generator = helpers.select_generator(
|
||||||
|
self.photodb.sql,
|
||||||
|
'SELECT photoid FROM album_photo_rel WHERE albumid == ?',
|
||||||
|
[self.id]
|
||||||
|
)
|
||||||
|
photos = [self.photodb.get_photo(id=fetch[0]) for fetch in generator]
|
||||||
|
photos.sort(key=lambda x: x.basename.lower())
|
||||||
|
return photos
|
||||||
|
|
||||||
def has_photo(self, photo):
|
def has_photo(self, photo):
|
||||||
if not isinstance(photo, Photo):
|
if not isinstance(photo, Photo):
|
||||||
raise TypeError('`photo` must be of type %s' % Photo)
|
raise TypeError('`photo` must be of type %s' % Photo)
|
||||||
|
@ -415,17 +426,6 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
result = super().leave_group(*args, **kwargs)
|
result = super().leave_group(*args, **kwargs)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def photos(self):
|
|
||||||
photos = []
|
|
||||||
generator = helpers.select_generator(
|
|
||||||
self.photodb.sql,
|
|
||||||
'SELECT photoid FROM album_photo_rel WHERE albumid == ?',
|
|
||||||
[self.id]
|
|
||||||
)
|
|
||||||
photos = [self.photodb.get_photo(id=fetch[0]) for fetch in generator]
|
|
||||||
photos.sort(key=lambda x: x.basename.lower())
|
|
||||||
return photos
|
|
||||||
|
|
||||||
@decorators.required_feature('album.edit')
|
@decorators.required_feature('album.edit')
|
||||||
@decorators.transaction
|
@decorators.transaction
|
||||||
def remove_photo(self, photo, *, commit=True):
|
def remove_photo(self, photo, *, commit=True):
|
||||||
|
@ -446,7 +446,7 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
def sum_bytes(self, recurse=True, string=False):
|
def sum_bytes(self, recurse=True, string=False):
|
||||||
if self._sum_bytes_local is None:
|
if self._sum_bytes_local is None:
|
||||||
#print(self, 'sumbytes cache miss local')
|
#print(self, 'sumbytes cache miss local')
|
||||||
photos = (photo for photo in self.photos() if photo.bytes is not None)
|
photos = (photo for photo in self.get_photos() if photo.bytes is not None)
|
||||||
self._sum_bytes_local = sum(photo.bytes for photo in photos)
|
self._sum_bytes_local = sum(photo.bytes for photo in photos)
|
||||||
total = self._sum_bytes_local
|
total = self._sum_bytes_local
|
||||||
|
|
||||||
|
@ -466,14 +466,14 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
if self._sum_photos_recursive is None:
|
if self._sum_photos_recursive is None:
|
||||||
#print(self, 'sumphotos cache miss')
|
#print(self, 'sumphotos cache miss')
|
||||||
total = 0
|
total = 0
|
||||||
total += sum(1 for x in self.photos())
|
total += sum(1 for x in self.get_photos())
|
||||||
total += sum(child.sum_photos() for child in self.get_children())
|
total += sum(child.sum_photos() for child in self.get_children())
|
||||||
self._sum_photos_recursive = total
|
self._sum_photos_recursive = total
|
||||||
|
|
||||||
return self._sum_photos_recursive
|
return self._sum_photos_recursive
|
||||||
|
|
||||||
def walk_photos(self):
|
def walk_photos(self):
|
||||||
yield from self.photos()
|
yield from self.get_photos()
|
||||||
children = self.walk_children()
|
children = self.walk_children()
|
||||||
# The first yield is itself
|
# The first yield is itself
|
||||||
next(children)
|
next(children)
|
||||||
|
|
|
@ -325,7 +325,7 @@ class PDBPhotoMixin:
|
||||||
def purge_empty_albums(self, *, commit=True):
|
def purge_empty_albums(self, *, commit=True):
|
||||||
albums = self.get_albums()
|
albums = self.get_albums()
|
||||||
for album in albums:
|
for album in albums:
|
||||||
if album.get_children() or album.photos():
|
if album.get_children() or album.get_photos():
|
||||||
continue
|
continue
|
||||||
album.delete(commit=False)
|
album.delete(commit=False)
|
||||||
if commit:
|
if commit:
|
||||||
|
|
|
@ -83,7 +83,7 @@ p
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% set photos = album.photos() %}
|
{% set photos = album.get_photos() %}
|
||||||
{% if photos %}
|
{% if photos %}
|
||||||
<h3>Photos</h3>
|
<h3>Photos</h3>
|
||||||
{% if view != "list" %}
|
{% if view != "list" %}
|
||||||
|
|
Loading…
Reference in a new issue