def view_post(id): """ Function the returns a single post for a comment to be added """ # all_category = postCategory.get_categories() # posts = Post.query.get(id) posts = Post.query.filter_by(id=id).first() print(posts) if posts is None: abort(404) posted_id = posts.id print(posted_id) # comment = Comments.get_comments(id) getComments = [] comments = Comments.get_comments() print(comments) for comment in comments: if comment.posts_id == posted_id: getComments.insert(0, comment) print(getComments) count_likes = Votes.query.filter_by(posts_id=id, vote=1).all() count_dislikes = Votes.query.filter_by(posts_id=id, vote=2).all() return render_template('view-post.html', posts=posts, comment=getComments, count_likes=len(count_likes), count_dislikes=len(count_dislikes))
def view_pitch(id): """ Function the returns a single pitch for a comment to be added """ # all_category = PitchCategory.get_categories() pitchess = Pitch.query.get(id) if pitchess is None: abort(404) comment = Comments.get_comments(id) print(comment) count_likes = Votes.query.filter_by(pitches_id=id, vote=1).all() count_dislikes = Votes.query.filter_by(pitches_id=id, vote=2).all() return render_template('view-pitch.html', pitches = pitchess, comment = comment, count_likes=len(count_likes), count_dislikes=len(count_dislikes))
def test_get_comment_by_id(self): self.new_comment.save_comment() got_comments = Comments.get_comments(10) self.assertTrue(len(got_comments) == 1)
def test_get_comment(self): self.new_comment.save_comment() got_coments = Comments.get_comments(12) self.assertTrue(len(got_coments) == 0)
def test_get_comment_by_id(self): self.new_comment.save_comment() rcvd_comments = Comments.get_comments(56789) self.assertTrue(len(rcvd_comments) == 1)