Add thumbnail_photo to Album.

This commit is contained in:
voussoir 2021-01-19 10:35:58 -08:00
parent a6f9d1859e
commit 95b95bc7be
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
5 changed files with 52 additions and 4 deletions

View file

@ -41,7 +41,7 @@ ffmpeg = _load_ffmpeg()
# Database #########################################################################################
DATABASE_VERSION = 17
DATABASE_VERSION = 18
DB_VERSION_PRAGMA = f'''
PRAGMA user_version = {DATABASE_VERSION};
'''
@ -62,8 +62,10 @@ CREATE TABLE IF NOT EXISTS albums(
title TEXT,
description TEXT,
created INT,
thumbnail_photo TEXT,
author_id TEXT,
FOREIGN KEY(author_id) REFERENCES users(id)
FOREIGN KEY(author_id) REFERENCES users(id),
FOREIGN KEY(thumbnail_photo) REFERENCES photos(id)
);
CREATE INDEX IF NOT EXISTS index_albums_id on albums(id);
CREATE INDEX IF NOT EXISTS index_albums_author_id on albums(author_id);

View file

@ -284,6 +284,7 @@ class Album(ObjectBase, GroupableMixin):
self.title = self.normalize_title(db_row['title'])
self.description = self.normalize_description(db_row['description'])
self.created = db_row['created']
self._thumbnail_photo = db_row['thumbnail_photo']
self.author_id = self.normalize_author_id(db_row['author_id'])
self.group_getter_many = self.photodb.get_albums_by_id
@ -532,6 +533,7 @@ class Album(ObjectBase, GroupableMixin):
'description': self.description,
'title': self.title,
'created': self.created,
'thumbnail_photo': self.thumbnail_photo.id if self._thumbnail_photo else None,
'author': self.get_author().jsonify() if self.author_id else None,
}
if not minimal:
@ -629,6 +631,16 @@ class Album(ObjectBase, GroupableMixin):
total = self.photodb.sql_select_one(query)[0]
return total
@property
def thumbnail_photo(self):
if self._thumbnail_photo is None:
return None
if isinstance(self._thumbnail_photo, Photo):
return self._thumbnail_photo
photo = self.photodb.get_photo(self._thumbnail_photo)
self._thumbnail_photo = photo
return photo
def walk_photos(self):
yield from self.get_photos()
children = self.walk_children()

View file

@ -38,7 +38,6 @@
.album_card_thumbnail
{
grid-area: thumbnail;
background-color: var(--color_transparency);
display: flex;
width: 100%;
height: 150px;

View file

@ -19,7 +19,12 @@ draggable=true
{% else %}
<a class="album_card_thumbnail" href="/album/{{album.id}}{{viewparam}}">
{% endif %}
<img src="/static/basic_thumbnails/album.png"/>
{% if album.thumbnail_photo %}
{% set thumbnail_src = "/thumbnail/" + album.thumbnail_photo.id + ".jpg" %}
{% else %}
{% set thumbnail_src = "/static/basic_thumbnails/album.png" %}
{% endif %}
<img src="{{thumbnail_src}}"/>
</a>
<div class="album_card_tools">

View file

@ -572,6 +572,36 @@ def upgrade_16_to_17(photodb):
m.go()
def upgrade_17_to_18(photodb):
'''
Added the thumbnail_photo column to albums.
'''
m = Migrator(photodb)
m.tables['albums']['create'] = '''
CREATE TABLE albums(
id TEXT PRIMARY KEY NOT NULL,
title TEXT,
description TEXT,
created INT,
thumbnail_photo TEXT,
author_id TEXT,
FOREIGN KEY(author_id) REFERENCES users(id),
FOREIGN KEY(thumbnail_photo) REFERENCES photos(id)
);
'''
m.tables['albums']['transfer'] = '''
INSERT INTO albums SELECT
id,
title,
description,
created,
NULL,
author_id
FROM albums_old;
'''
m.go()
def upgrade_all(data_directory):
'''
Given the directory containing a phototagger database, apply all of the