From 95b95bc7bec388d2d4d309163318b7a5baface9b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 19 Jan 2021 10:35:58 -0800 Subject: [PATCH] Add thumbnail_photo to Album. --- etiquette/constants.py | 6 ++-- etiquette/objects.py | 12 ++++++++ .../etiquette_flask/static/css/cards.css | 1 - .../etiquette_flask/templates/album_card.html | 7 ++++- utilities/database_upgrader.py | 30 +++++++++++++++++++ 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/etiquette/constants.py b/etiquette/constants.py index a8733cf..ffaf62a 100644 --- a/etiquette/constants.py +++ b/etiquette/constants.py @@ -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); diff --git a/etiquette/objects.py b/etiquette/objects.py index 28710de..57b5307 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -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() diff --git a/frontends/etiquette_flask/static/css/cards.css b/frontends/etiquette_flask/static/css/cards.css index 4c338e6..68f0f1a 100644 --- a/frontends/etiquette_flask/static/css/cards.css +++ b/frontends/etiquette_flask/static/css/cards.css @@ -38,7 +38,6 @@ .album_card_thumbnail { grid-area: thumbnail; - background-color: var(--color_transparency); display: flex; width: 100%; height: 150px; diff --git a/frontends/etiquette_flask/templates/album_card.html b/frontends/etiquette_flask/templates/album_card.html index d68900d..694015a 100644 --- a/frontends/etiquette_flask/templates/album_card.html +++ b/frontends/etiquette_flask/templates/album_card.html @@ -19,7 +19,12 @@ draggable=true {% else %} {% endif %} - + {% if album.thumbnail_photo %} + {% set thumbnail_src = "/thumbnail/" + album.thumbnail_photo.id + ".jpg" %} + {% else %} + {% set thumbnail_src = "/static/basic_thumbnails/album.png" %} + {% endif %} +
diff --git a/utilities/database_upgrader.py b/utilities/database_upgrader.py index 6584238..838bb3b 100644 --- a/utilities/database_upgrader.py +++ b/utilities/database_upgrader.py @@ -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