Beispiel #1
0
    def get(self, **kwargs):
        template = jinja_env.get_template('post.html')
        post_id = kwargs['post_id']
        post = Post.get_by_id(int(post_id))

        # Retrieve all comments
        comments_query = Comment.query(Comment.post_id == int(post_id)).order(
            Comment.submitted)
        comments = [comment for comment in comments_query]

        # Discern anonymous browsers from users
        cookie = self.request.cookies.get('user')
        user = None
        has_liked = None
        if validate_user_cookie(cookie):
            user = cookie.split("|")[0]
            has_liked = user_has_liked_post(user, post_id)

        # If this post exists, render it (otherwise, 404)
        self.write(
            template, {
                'post': post,
                'comments': comments,
                'current_user': user,
                'has_liked': has_liked
            })
Beispiel #2
0
    def get(self, **kwargs):
        post_id = kwargs['post_id']
        Post.get_by_id(int(post_id)).key.delete()

        # Cascade the delete to all comments associated with the post
        comments = Comment.query(Comment.post_id == int(post_id))
        for comment in comments:
            comment.key.delete()
        self.redirect('/')
Beispiel #3
0
    def get(self, **kwargs):
        template = jinja_env.get_template('edit-form.html')
        post_id = kwargs['post_id']
        comment_id = kwargs['comment_id']

        # Retrieve Post and its Comment(s) from the datastore
        post = Post.get_by_id(int(post_id))
        comments_query = Comment.query(Comment.post_id == int(post_id)).order(
            Comment.submitted)
        comments = [comment for comment in comments_query]

        self.write(template, {
            'post': post,
            'edit_comment_id': int(comment_id),
            'comments': comments
        })