From b28f689077719b450f67d9f127b9aeec8e30d6bb Mon Sep 17 00:00:00 2001 From: rr- Date: Mon, 6 Jun 2016 20:57:12 +0200 Subject: [PATCH] server/posts: add ownFavorite field to posts --- API.md | 3 +++ server/szurubooru/func/posts.py | 3 +++ server/szurubooru/tests/func/test_posts.py | 1 + 3 files changed, 7 insertions(+) diff --git a/API.md b/API.md index db89baf..6a4ed37 100644 --- a/API.md +++ b/API.md @@ -1549,6 +1549,7 @@ One file together with its metadata posted to the site. "user": , "score": , "ownScore": , + "ownFavorite": , "tagCount": , "favoriteCount": , "commentCount": , @@ -1612,6 +1613,8 @@ One file together with its metadata posted to the site. - ``: the collective score (+1/-1 rating) of the given post. - ``: the score (+1/-1 rating) of the given post by the authenticated user. +- ``: whether the authenticated user has given post in their + favorites. - ``: how many tags the post is tagged with - ``: how many users have the post in their favorites - ``: how many comments are filed under that post diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index 28d4f33..8c281b9 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -93,6 +93,9 @@ def serialize_post(post, authenticated_user, options=None): 'user': lambda: users.serialize_micro_user(post.user), 'score': lambda: post.score, 'ownScore': lambda: scores.get_score(post, authenticated_user), + 'ownFavorite': lambda: len( + [user for user in post.favorited_by \ + if user.user_id == authenticated_user.user_id]) > 0, 'tagCount': lambda: post.tag_count, 'favoriteCount': lambda: post.favorite_count, 'commentCount': lambda: post.comment_count, diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index 8386500..594fcec 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -147,6 +147,7 @@ def test_serialize_post( 'notes': [], 'user': 'post author', 'score': 1, + 'ownFavorite': False, 'ownScore': -1, 'tagCount': 2, 'favoriteCount': 1,