Update digest_directory to handle plural albums at every step.
This commit is contained in:
parent
dea746c45a
commit
4a3236babe
1 changed files with 28 additions and 21 deletions
|
@ -1355,30 +1355,36 @@ class PDBUtilMixin:
|
||||||
photos.append(photo)
|
photos.append(photo)
|
||||||
return photos
|
return photos
|
||||||
|
|
||||||
def create_or_fetch_current_album(albums_by_path, current_directory):
|
def create_or_fetch_current_albums(albums_by_path, current_directory):
|
||||||
current_album = albums_by_path.get(current_directory.absolute_path, None)
|
current_albums = albums_by_path.get(current_directory.absolute_path, None)
|
||||||
if current_album is not None:
|
if current_albums is not None:
|
||||||
return current_album
|
return current_albums
|
||||||
|
|
||||||
try:
|
current_albums = list(self.get_albums_by_path(current_directory.absolute_path))
|
||||||
current_album = self.get_album_by_path(current_directory.absolute_path)
|
if not current_albums:
|
||||||
except exceptions.NoSuchAlbum:
|
current_albums = [self.new_album(
|
||||||
current_album = self.new_album(
|
associated_directories=current_directory.absolute_path,
|
||||||
associated_directory=current_directory.absolute_path,
|
|
||||||
title=current_directory.basename,
|
title=current_directory.basename,
|
||||||
)
|
)]
|
||||||
albums_by_path[current_directory.absolute_path] = current_album
|
|
||||||
return current_album
|
|
||||||
|
|
||||||
def orphan_join_parent_album(albums_by_path, current_album, current_directory):
|
albums_by_path[current_directory.absolute_path] = current_albums
|
||||||
|
return current_albums
|
||||||
|
|
||||||
|
def orphan_join_parent_albums(albums_by_path, current_albums, current_directory):
|
||||||
'''
|
'''
|
||||||
If the current album is an orphan, let's check if there exists an
|
If the current album is an orphan, let's check if there exists an
|
||||||
album for the parent directory. If so, add the current album to it.
|
album for the parent directory. If so, add the current album to it.
|
||||||
'''
|
'''
|
||||||
if not current_album.has_any_parent():
|
orphans = [album for album in current_albums if not album.has_any_parent()]
|
||||||
parent = albums_by_path.get(current_directory.parent.absolute_path, None)
|
if not orphans:
|
||||||
if parent is not None:
|
return
|
||||||
parent.add_child(current_album)
|
|
||||||
|
parents = albums_by_path.get(current_directory.parent.absolute_path, None)
|
||||||
|
if not parents:
|
||||||
|
return
|
||||||
|
|
||||||
|
for parent in parents:
|
||||||
|
parent.add_children(orphans)
|
||||||
|
|
||||||
directory = _normalize_directory(directory)
|
directory = _normalize_directory(directory)
|
||||||
exclude_directories = _normalize_exclude_directories(exclude_directories)
|
exclude_directories = _normalize_exclude_directories(exclude_directories)
|
||||||
|
@ -1388,7 +1394,7 @@ class PDBUtilMixin:
|
||||||
|
|
||||||
if make_albums:
|
if make_albums:
|
||||||
albums_by_path = {}
|
albums_by_path = {}
|
||||||
main_album = create_or_fetch_current_album(albums_by_path, directory)
|
main_album = create_or_fetch_current_albums(albums_by_path, directory)
|
||||||
|
|
||||||
walk_generator = spinal.walk_generator(
|
walk_generator = spinal.walk_generator(
|
||||||
directory,
|
directory,
|
||||||
|
@ -1407,10 +1413,11 @@ class PDBUtilMixin:
|
||||||
if not make_albums:
|
if not make_albums:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
current_album = create_or_fetch_current_album(albums_by_path, current_directory)
|
current_albums = create_or_fetch_current_albums(albums_by_path, current_directory)
|
||||||
orphan_join_parent_album(albums_by_path, current_album, current_directory)
|
orphan_join_parent_albums(albums_by_path, current_albums, current_directory)
|
||||||
|
|
||||||
current_album.add_photos(photos)
|
for album in current_albums:
|
||||||
|
album.add_photos(photos)
|
||||||
|
|
||||||
if make_albums:
|
if make_albums:
|
||||||
return main_album
|
return main_album
|
||||||
|
|
Loading…
Reference in a new issue