From fdcf07940af9a5f8aef7cf60c30edc7b7333ad5e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 16 Feb 2018 23:00:43 -0800 Subject: [PATCH] Rename Groupable.children -> get_children. --- etiquette/helpers.py | 2 +- etiquette/jsonify.py | 2 +- etiquette/objects.py | 40 +++++++++---------- etiquette/photodb.py | 2 +- etiquette/tag_export.py | 2 +- .../etiquette_flask/templates/album.html | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/etiquette/helpers.py b/etiquette/helpers.py index ce0aeed..d1c833c 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -29,7 +29,7 @@ def album_zip_directories(album, recursive=True): directories[album] = root_folder if recursive: - for child_album in album.children(): + for child_album in album.get_children(): child_directories = album_zip_directories(child_album, recursive=True) for (child_album, child_directory) in child_directories.items(): child_directory = os.path.join(root_folder, child_directory) diff --git a/etiquette/jsonify.py b/etiquette/jsonify.py index f96c711..f0f9d28 100644 --- a/etiquette/jsonify.py +++ b/etiquette/jsonify.py @@ -16,7 +16,7 @@ def album(a, minimal=False): j['parent'] = album(parent, minimal=True) else: j['parent'] = None - j['sub_albums'] = [child.id for child in a.children()] + j['sub_albums'] = [child.id for child in a.get_children()] return j diff --git a/etiquette/objects.py b/etiquette/objects.py index d9d6021..0a9bed3 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -94,22 +94,6 @@ class GroupableMixin: self.photodb.log.debug('Committing - add to group') self.photodb.commit() - def children(self): - cur = self.photodb.sql.cursor() - - cur.execute('SELECT memberid FROM %s WHERE parentid == ?' % self.group_table, [self.id]) - fetches = cur.fetchall() - results = [] - for fetch in fetches: - memberid = fetch[0] - child = self.group_getter(id=memberid) - results.append(child) - if isinstance(self, Tag): - results.sort(key=lambda x: x.name) - else: - results.sort(key=lambda x: x.id) - return results - @decorators.transaction def delete(self, *, delete_children=False, commit=True): ''' @@ -127,7 +111,7 @@ class GroupableMixin: self.photodb._cached_frozen_children = None cur = self.photodb.sql.cursor() if delete_children: - for child in self.children(): + for child in self.get_children(): child.delete(delete_children=delete_children, commit=False) else: # Lift children @@ -156,6 +140,22 @@ class GroupableMixin: self.photodb.log.debug('Committing - delete tag') self.photodb.commit() + def get_children(self): + cur = self.photodb.sql.cursor() + + cur.execute('SELECT memberid FROM %s WHERE parentid == ?' % self.group_table, [self.id]) + fetches = cur.fetchall() + results = [] + for fetch in fetches: + memberid = fetch[0] + child = self.group_getter(id=memberid) + results.append(child) + if isinstance(self, Tag): + results.sort(key=lambda x: x.name) + else: + results.sort(key=lambda x: x.id) + return results + def get_parent(self): ''' Return the group of which this is a member, or None. @@ -204,7 +204,7 @@ class GroupableMixin: def walk_children(self): yield self - for child in self.children(): + for child in self.get_children(): yield from child.walk_children() def walk_parents(self): @@ -453,7 +453,7 @@ class Album(ObjectBase, GroupableMixin): if recurse: if self._sum_bytes_recursive is None: #print(self, 'sumbytes cache miss recursive') - child_bytes = sum(child.sum_bytes(recurse=True) for child in self.children()) + child_bytes = sum(child.sum_bytes(recurse=True) for child in self.get_children()) self._sum_bytes_recursive = self._sum_bytes_local + child_bytes total = self._sum_bytes_recursive @@ -467,7 +467,7 @@ class Album(ObjectBase, GroupableMixin): #print(self, 'sumphotos cache miss') total = 0 total += sum(1 for x in self.photos()) - total += sum(child.sum_photos() for child in self.children()) + total += sum(child.sum_photos() for child in self.get_children()) self._sum_photos_recursive = total return self._sum_photos_recursive diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 0798cd9..72798f7 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.children() or album.photos(): + if album.get_children() or album.photos(): continue album.delete(commit=False) if commit: diff --git a/etiquette/tag_export.py b/etiquette/tag_export.py index fc0b38e..7384a37 100644 --- a/etiquette/tag_export.py +++ b/etiquette/tag_export.py @@ -87,7 +87,7 @@ def qualified_names(tags): def stdout(tags, depth=0): for tag in tags: - children = tag.children() + children = tag.get_children() synonyms = tag.synonyms() pad = ' ' * depth diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index 87bec78..7430d51 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -74,7 +74,7 @@ p