def getVisibleToAuthor(viewer=None, author=None, time_line=False, localOnly=False): resultList = [] if author is None: postList = Post.objects.all() else: postList = Post.objects.filter(author=author) for post in postList: if post.isViewable(viewer, post.author): # if we are should timeline only, then we need to check whether or not the # two are friends if post.content_type == Post.MARK_DOWN: post.content = markdown.markdown(post.content, safe_mode='escape') if time_line: if (viewer == post.author or FriendRequest.is_friend(viewer, post.author) or FriendRequest.is_following_or_made_request( viewer, post.author)): resultList.append(get_post_json(post)) else: resultList.append(get_post_json(post)) if localOnly is False: if not time_line: remote_posts = remote_helper.api_getPublicPost() for post in remote_posts: if post['content-type'] == Post.MARK_DOWN: post['content_type'] = Post.MARK_DOWN post['content'] = markdown.markdown(post['content'], safe_mode='escape') else: friend_posts = [] authorID = author.get_uuid() if author is not None else None remote_posts = remote_helper.api_getPostByAuthorID( viewer, authorID) for post in remote_posts: if post['content-type'] == Post.MARK_DOWN: post['content_type'] = Post.MARK_DOWN post['content'] = markdown.markdown(post['content'], safe_mode='escape') author = post['author'] author = Author.objects.filter(uuid=author['id']) if len(author) > 0: author = author.first() if FriendRequest.is_following_or_made_request( author, viewer) or FriendRequest.is_friend( author, viewer): friend_posts.append(post) remote_posts = friend_posts resultList.extend(remote_posts) return resultList
def getVisibleToAuthor(viewer=None, author=None, time_line=False, localOnly=False): resultList = [] if author is None: postList = Post.objects.all() else: postList = Post.objects.filter(author=author) for post in postList: if post.isViewable(viewer, post.author): # if we are should timeline only, then we need to check whether or not the # two are friends if post.content_type == Post.MARK_DOWN: post.content = markdown.markdown(post.content, safe_mode='escape') if time_line: if (viewer == post.author or FriendRequest.is_friend(viewer, post.author) or FriendRequest.is_following_or_made_request(viewer, post.author)): resultList.append(get_post_json(post)) else: resultList.append(get_post_json(post)) if localOnly is False: if not time_line: remote_posts = remote_helper.api_getPublicPost() for post in remote_posts: if post['content-type'] == Post.MARK_DOWN: post['content_type'] = Post.MARK_DOWN post['content'] = markdown.markdown(post['content'], safe_mode='escape') else: friend_posts = [] authorID = author.get_uuid() if author is not None else None remote_posts = remote_helper.api_getPostByAuthorID(viewer, authorID) for post in remote_posts: if post['content-type'] == Post.MARK_DOWN: post['content_type'] = Post.MARK_DOWN post['content'] = markdown.markdown(post['content'], safe_mode='escape') author = post['author'] author = Author.objects.filter(uuid=author['id']) if len(author) > 0: author = author.first() if FriendRequest.is_following_or_made_request(author, viewer) or FriendRequest.is_friend(author, viewer): friend_posts.append(post) remote_posts = friend_posts resultList.extend(remote_posts) return resultList
def _getAllPosts(viewer, postAuthor=None, time_line=False, remoteOnly=False): data = {} if remoteOnly: post_list = remote_helper.api_getPostByAuthorID(viewer, postAuthor) print(len(post_list)) else: post_list = post_utils.getVisibleToAuthor(viewer=viewer, author=postAuthor, time_line=time_line) if viewer is not None: post_list.extend(_get_github_events(viewer)) data['posts'] = _getDetailedPosts(post_list) data['visibility'] = post_utils.getVisibilityTypes() return data