Fix toplevel albums not getting digest children; prefix album zips with 'album '
This commit is contained in:
parent
92880ba3eb
commit
415d858e20
4 changed files with 16 additions and 14 deletions
|
@ -16,9 +16,9 @@ def album_zip_directories(album, recursive=True):
|
||||||
'''
|
'''
|
||||||
directories = {}
|
directories = {}
|
||||||
if album.title:
|
if album.title:
|
||||||
root_folder = '%s - %s' % (album.id, normalize_filepath(album.title))
|
root_folder = 'album %s - %s' % (album.id, normalize_filepath(album.title))
|
||||||
else:
|
else:
|
||||||
root_folder = '%s' % album.id
|
root_folder = 'album %s' % album.id
|
||||||
|
|
||||||
directories[album] = root_folder
|
directories[album] = root_folder
|
||||||
if recursive:
|
if recursive:
|
||||||
|
|
|
@ -42,6 +42,7 @@ class GroupableMixin:
|
||||||
if not isinstance(member, type(self)):
|
if not isinstance(member, type(self)):
|
||||||
raise TypeError('Member must be of type %s' % type(self))
|
raise TypeError('Member must be of type %s' % type(self))
|
||||||
|
|
||||||
|
self.photodb.log.debug('Adding child %s to %s' % (member, self))
|
||||||
# Groupables are only allowed to have 1 parent.
|
# Groupables are only allowed to have 1 parent.
|
||||||
# Unlike photos which can exist in multiple albums.
|
# Unlike photos which can exist in multiple albums.
|
||||||
cur = self.photodb.sql.cursor()
|
cur = self.photodb.sql.cursor()
|
||||||
|
@ -192,6 +193,7 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
raise ValueError('Not the same PhotoDB')
|
raise ValueError('Not the same PhotoDB')
|
||||||
if self.has_photo(photo):
|
if self.has_photo(photo):
|
||||||
return
|
return
|
||||||
|
self.photodb.log.debug('Adding photo %s to %s' % (photo, self))
|
||||||
cur = self.photodb.sql.cursor()
|
cur = self.photodb.sql.cursor()
|
||||||
cur.execute('INSERT INTO album_photo_rel VALUES(?, ?)', [self.id, photo.id])
|
cur.execute('INSERT INTO album_photo_rel VALUES(?, ?)', [self.id, photo.id])
|
||||||
if commit:
|
if commit:
|
||||||
|
@ -226,6 +228,7 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
title = self.title
|
title = self.title
|
||||||
if description is None:
|
if description is None:
|
||||||
description = self.description
|
description = self.description
|
||||||
|
cur = self.photodb.sql.cursor()
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'UPDATE albums SET title=?, description=? WHERE id == ?',
|
'UPDATE albums SET title=?, description=? WHERE id == ?',
|
||||||
[title, description, self.id]
|
[title, description, self.id]
|
||||||
|
|
|
@ -296,6 +296,7 @@ class PDBAlbumMixin:
|
||||||
if not isinstance(description, str):
|
if not isinstance(description, str):
|
||||||
raise TypeError('Description must be string, not %s' % type(description))
|
raise TypeError('Description must be string, not %s' % type(description))
|
||||||
|
|
||||||
|
self.log.debug('New Album: %s' % title)
|
||||||
data = {
|
data = {
|
||||||
'id': albumid,
|
'id': albumid,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
@ -1236,21 +1237,16 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs
|
||||||
commit=False,
|
commit=False,
|
||||||
title=current_location.basename,
|
title=current_location.basename,
|
||||||
)
|
)
|
||||||
self.log.debug('Created %s' % current_album.title)
|
|
||||||
albums[current_location.absolute_path] = current_album
|
albums[current_location.absolute_path] = current_album
|
||||||
|
|
||||||
# Add the current directory album to the parent directory album.
|
|
||||||
# Add the photos to the current album.
|
|
||||||
parent = albums.get(current_location.parent.absolute_path, None)
|
parent = albums.get(current_location.parent.absolute_path, None)
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
try:
|
try:
|
||||||
parent.add(current_album, commit=False)
|
parent.add(current_album, commit=False)
|
||||||
self.log.debug('Added child album to %s' % parent.title)
|
|
||||||
except exceptions.GroupExists:
|
except exceptions.GroupExists:
|
||||||
pass
|
pass
|
||||||
self.log.debug('Added photo to %s' % current_album)
|
for photo in new_photos:
|
||||||
for photo in new_photos:
|
current_album.add_photo(photo, commit=False)
|
||||||
current_album.add_photo(photo, commit=False)
|
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
self.log.debug('Committing - digest')
|
self.log.debug('Committing - digest')
|
||||||
|
|
|
@ -315,21 +315,23 @@ def get_album_zip(albumid):
|
||||||
for (inner_album, directory) in directories.items():
|
for (inner_album, directory) in directories.items():
|
||||||
text = []
|
text = []
|
||||||
if inner_album.title:
|
if inner_album.title:
|
||||||
text.append(inner_album.title)
|
text.append('Title: ' + inner_album.title)
|
||||||
if inner_album.description:
|
if inner_album.description:
|
||||||
text.append(inner_album.description)
|
text.append('Description: ' + inner_album.description)
|
||||||
if not text:
|
if not text:
|
||||||
continue
|
continue
|
||||||
text = '\r\n\r\n'.join(text)
|
text = '\r\n\r\n'.join(text)
|
||||||
streamed_zip.writestr(
|
streamed_zip.writestr(
|
||||||
arcname=os.path.join(directory, '%s.txt' % inner_album.id),
|
arcname=os.path.join(directory, 'album %s.txt' % inner_album.id),
|
||||||
data=text.encode('utf-8'),
|
data=text.encode('utf-8'),
|
||||||
)
|
)
|
||||||
|
|
||||||
if album.title:
|
if album.title:
|
||||||
download_as = '%s - %s.zip' % (album.id, album.title)
|
download_as = 'album %s - %s.zip' % (album.id, album.title)
|
||||||
else:
|
else:
|
||||||
download_as = '%s.zip' % album.id
|
download_as = 'album %s.zip' % album.id
|
||||||
|
|
||||||
|
download_as = helpers.normalize_filepath(download_as)
|
||||||
download_as = urllib.parse.quote(download_as)
|
download_as = urllib.parse.quote(download_as)
|
||||||
outgoing_headers = {
|
outgoing_headers = {
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
|
@ -384,6 +386,7 @@ def get_file(photoid):
|
||||||
else:
|
else:
|
||||||
download_as = photo.id + photo.dot_extension
|
download_as = photo.id + photo.dot_extension
|
||||||
|
|
||||||
|
download_as = helpers.normalize_filepath(download_as)
|
||||||
download_as = urllib.parse.quote(download_as)
|
download_as = urllib.parse.quote(download_as)
|
||||||
response = flask.make_response(send_file(photo.real_filepath))
|
response = flask.make_response(send_file(photo.real_filepath))
|
||||||
response.headers['Content-Disposition'] = 'attachment; filename*=UTF-8\'\'%s' % download_as
|
response.headers['Content-Disposition'] = 'attachment; filename*=UTF-8\'\'%s' % download_as
|
||||||
|
|
Loading…
Reference in a new issue