server/posts: add ownFavorite field to posts

This commit is contained in:
rr-
2016-06-06 20:57:12 +02:00
parent 93a5af2097
commit b28f689077
3 changed files with 7 additions and 0 deletions

View File

@ -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,

View File

@ -147,6 +147,7 @@ def test_serialize_post(
'notes': [],
'user': 'post author',
'score': 1,
'ownFavorite': False,
'ownScore': -1,
'tagCount': 2,
'favoriteCount': 1,