def _post_info(post): info = post.to_dict() favorites = Favorite.count_by_post(post.id) up_votes = PostUpVote.count_by_post(post.id) down_votes = PostDownVote.count_by_post(post.id) latest_comment = Comment.latest_by_post(post.id) comment_count = Comment.count_by_post(post.id) if latest_comment: latest_comment_user = User.get(latest_comment.author_id).username latest_comment_date = latest_comment.date else: latest_comment_user = None latest_comment_date = None info.update({ 'up_votes': up_votes, 'down_votes': down_votes, 'favorites': favorites, 'latest_comment_user': latest_comment_user, 'latest_comment_date': latest_comment_date, 'comment_count': comment_count, }) return info