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 %} +