Replace create_or_get_photos with singular.
This commit is contained in:
parent
7d2e5bd9a9
commit
6eb4d887ba
1 changed files with 15 additions and 18 deletions
|
@ -1552,26 +1552,23 @@ class PDBUtilMixin:
|
||||||
photo.relocate(filepath.absolute_path)
|
photo.relocate(filepath.absolute_path)
|
||||||
return photo
|
return photo
|
||||||
|
|
||||||
def create_or_fetch_photos(filepaths, new_photo_kwargs):
|
def create_or_fetch_photo(filepath, new_photo_kwargs):
|
||||||
'''
|
'''
|
||||||
Given an iterable of filepaths, find the corresponding Photo object
|
Given a filepath, find the corresponding Photo object if it exists,
|
||||||
if it exists, otherwise create it and then return it.
|
otherwise create it and then return it.
|
||||||
'''
|
'''
|
||||||
photos = []
|
try:
|
||||||
for filepath in filepaths:
|
photo = self.get_photo_by_path(filepath)
|
||||||
try:
|
except exceptions.NoSuchPhoto:
|
||||||
photo = self.get_photo_by_path(filepath)
|
photo = None
|
||||||
except exceptions.NoSuchPhoto:
|
if not photo:
|
||||||
photo = None
|
photo = check_renamed_inode(filepath)
|
||||||
if not photo:
|
if not photo:
|
||||||
photo = check_renamed_inode(filepath)
|
photo = self.new_photo(filepath.absolute_path, **new_photo_kwargs)
|
||||||
if not photo:
|
if new_photo_ratelimit is not None:
|
||||||
photo = self.new_photo(filepath.absolute_path, **new_photo_kwargs)
|
new_photo_ratelimit.limit()
|
||||||
if new_photo_ratelimit is not None:
|
|
||||||
new_photo_ratelimit.limit()
|
|
||||||
|
|
||||||
photos.append(photo)
|
return photo
|
||||||
return photos
|
|
||||||
|
|
||||||
def create_or_fetch_current_albums(albums_by_path, current_directory):
|
def create_or_fetch_current_albums(albums_by_path, current_directory):
|
||||||
current_albums = albums_by_path.get(current_directory.absolute_path, None)
|
current_albums = albums_by_path.get(current_directory.absolute_path, None)
|
||||||
|
@ -1625,7 +1622,7 @@ class PDBUtilMixin:
|
||||||
if natural_sort:
|
if natural_sort:
|
||||||
files = sorted(files, key=lambda f: helpers.natural_sorter(f.basename))
|
files = sorted(files, key=lambda f: helpers.natural_sorter(f.basename))
|
||||||
|
|
||||||
photos = create_or_fetch_photos(files, new_photo_kwargs=new_photo_kwargs)
|
photos = [create_or_fetch_photo(file, new_photo_kwargs=new_photo_kwargs) for file in files]
|
||||||
|
|
||||||
if yield_photos:
|
if yield_photos:
|
||||||
yield from photos
|
yield from photos
|
||||||
|
|
Loading…
Reference in a new issue