From 4f1471c41e3258a30bc4f68d7c120296f9b4c60a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 9 Jan 2021 10:54:10 -0800 Subject: [PATCH] Add User.get_albums, bookmarks, photos, tags. --- etiquette/objects.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/etiquette/objects.py b/etiquette/objects.py index 5a49fb4..c1857c6 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -1700,6 +1700,42 @@ class User(ObjectBase): else: return self._display_name + def get_albums(self, *, direction='asc'): + if direction.lower() not in {'asc', 'desc'}: + raise ValueError(direction) + + return self.photodb.get_albums_by_sql( + f'SELECT * FROM albums WHERE author_id == ? ORDER BY created {direction}', + [self.id] + ) + + def get_bookmarks(self, *, direction='asc'): + if direction.lower() not in {'asc', 'desc'}: + raise ValueError(direction) + + return self.photodb.get_bookmarks_by_sql( + f'SELECT * FROM bookmarks WHERE author_id == ? ORDER BY created {direction}', + [self.id] + ) + + def get_photos(self, *, direction='asc'): + if direction.lower() not in {'asc', 'desc'}: + raise ValueError(direction) + + return self.photodb.get_photos_by_sql( + f'SELECT * FROM photos WHERE author_id == ? ORDER BY created {direction}', + [self.id] + ) + + def get_tags(self, *, direction='asc'): + if direction.lower() not in {'asc', 'desc'}: + raise ValueError(direction) + + return self.photodb.get_tags_by_sql( + f'SELECT * FROM tags WHERE author_id == ? ORDER BY created {direction}', + [self.id] + ) + def jsonify(self): j = { 'type': 'user',