From 5bc3fdd08e393ed731a154b3fc019a0df6649e65 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 15 Sep 2020 13:44:28 -0700 Subject: [PATCH] Move purge_empty_albums to PDBAlbumMixin. --- etiquette/photodb.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 2eebc4b..20be5ab 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -120,6 +120,23 @@ class PDBAlbumMixin: return album + @decorators.transaction + def purge_empty_albums(self, albums=None): + if albums is None: + to_check = set(self.get_albums()) + else: + to_check = set() + for album in albums: + to_check.update(album.walk_children()) + + while to_check: + album = to_check.pop() + if album.get_children() or album.get_photos(): + continue + # This may have been the last child of an otherwise empty parent. + to_check.update(album.get_parents()) + album.delete() + class PDBBookmarkMixin: def __init__(self): @@ -486,23 +503,6 @@ class PDBPhotoMixin: continue photo.delete() - @decorators.transaction - def purge_empty_albums(self, albums=None): - if albums is None: - to_check = set(self.get_albums()) - else: - to_check = set() - for album in albums: - to_check.update(album.walk_children()) - - while to_check: - album = to_check.pop() - if album.get_children() or album.get_photos(): - continue - # This may have been the last child of an otherwise empty parent. - to_check.update(album.get_parents()) - album.delete() - def search( self, *,