From e77a2209eb671bdd2e726d5c4d69e8d939ca7f9f Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 20 Jan 2021 17:03:37 -0800 Subject: [PATCH] Add Album.set_thumbnail_photo. --- etiquette/objects.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/etiquette/objects.py b/etiquette/objects.py index 57b5307..72f89ee 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -576,6 +576,28 @@ class Album(ObjectBase, GroupableMixin): for photo in remove_photos: self._remove_photo(photo) + @decorators.required_feature('album.edit') + @decorators.transaction + def set_thumbnail_photo(self, photo): + if photo is None: + photo_id = None + elif isinstance(photo, str): + photo = self.photodb.get_photo(photo) + photo_id = photo.id + elif isinstance(photo, Photo): + photo.__reinit__() + photo.assert_not_deleted() + photo_id = photo.id + else: + raise TypeError(f'Must be {Photo}, not {type(photo)}.') + + pairs = { + 'id': self.id, + 'thumbnail_photo': photo_id, + } + self.photodb.sql_update(table='albums', pairs=pairs, where_key='id') + self._thumbnail_photo = photo + def sum_bytes(self, recurse=True): query = stringtools.collapse_whitespace(''' SELECT SUM(bytes) FROM photos