From ac9d7ede229470750b25e1f63a2390f22f4cf7f0 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 16 Feb 2018 23:03:54 -0800 Subject: [PATCH] Rename Album.photos -> get_photos. --- etiquette/helpers.py | 2 +- etiquette/jsonify.py | 2 +- etiquette/objects.py | 30 +++++++++---------- etiquette/photodb.py | 2 +- .../etiquette_flask/templates/album.html | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/etiquette/helpers.py b/etiquette/helpers.py index d1c833c..7bf278c 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -47,7 +47,7 @@ def album_zip_filenames(album, recursive=True): arcnames = {} directories = album_zip_directories(album, recursive=recursive) for (album, directory) in directories.items(): - photos = album.photos() + photos = album.get_photos() for photo in photos: if photo.real_filepath in arcnames: continue diff --git a/etiquette/jsonify.py b/etiquette/jsonify.py index db7cdae..d5aa263 100644 --- a/etiquette/jsonify.py +++ b/etiquette/jsonify.py @@ -10,7 +10,7 @@ def album(a, minimal=False): 'title': a.title, } 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() if parent is not None: j['parent'] = album(parent, minimal=True) diff --git a/etiquette/objects.py b/etiquette/objects.py index 86d9ba2..7aeb7b3 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -326,7 +326,7 @@ class Album(ObjectBase, GroupableMixin): if nested_children: photos = self.walk_photos() else: - photos = self.photos() + photos = self.get_photos() for photo in photos: photo.add_tag(tag, commit=False) @@ -392,6 +392,17 @@ class Album(ObjectBase, GroupableMixin): self.photodb.log.debug('Committing - edit album') 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): if not isinstance(photo, Photo): raise TypeError('`photo` must be of type %s' % Photo) @@ -415,17 +426,6 @@ class Album(ObjectBase, GroupableMixin): result = super().leave_group(*args, **kwargs) 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.transaction def remove_photo(self, photo, *, commit=True): @@ -446,7 +446,7 @@ class Album(ObjectBase, GroupableMixin): def sum_bytes(self, recurse=True, string=False): if self._sum_bytes_local is None: #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) total = self._sum_bytes_local @@ -466,14 +466,14 @@ class Album(ObjectBase, GroupableMixin): if self._sum_photos_recursive is None: #print(self, 'sumphotos cache miss') 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()) self._sum_photos_recursive = total return self._sum_photos_recursive def walk_photos(self): - yield from self.photos() + yield from self.get_photos() children = self.walk_children() # The first yield is itself next(children) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 72798f7..d3efadc 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -325,7 +325,7 @@ class PDBPhotoMixin: def purge_empty_albums(self, *, commit=True): albums = self.get_albums() for album in albums: - if album.get_children() or album.photos(): + if album.get_children() or album.get_photos(): continue album.delete(commit=False) if commit: diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index 7430d51..fc12fe8 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -83,7 +83,7 @@ p - {% set photos = album.photos() %} + {% set photos = album.get_photos() %} {% if photos %}

Photos

{% if view != "list" %}