Example #1
0
    def get(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')

        if user_cookie:
            user_id_cookie = user_cookie.split('|')[0]
        else:
            user_id_cookie = False

        check_like = db.GqlQuery("SELECT * FROM Like WHERE "
                                 "user_id = :1 AND post_id = :2",
                                 int(user_id_cookie), int(post_id))
        if check_like.count():
            if_user_liked = True
        else:
            if_user_liked = False

        comment = db.Query(Comment).filter(
            'post_id =', int(post_id)).order('-created')

        self.render(
            "post.html",
            posts=[post_exists(post_id)],
            user_owns_post=user_owns_post(post_id, user_id_cookie),
            comments=comment,
            user_id_cookie=int(user_id_cookie),
            user_cookie=user_cookie,
            if_user_liked=if_user_liked)
Example #2
0
    def post(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')
        subject = self.request.get("subject")
        content = self.request.get("content")
        if user_cookie:
            if user_logged_in(user_cookie):
                if subject and content:
                    p = Post.get_by_id(int(post_id))
                    p.subject = subject
                    p.content = content
                    p = p.put()

                    self.redirect("/post/%d" % p.id())
                else:
                    error = "We need the subject and some content!"
                    self.render("edit-post.html", subject=subject,
                                content=content, user_cookie=user_cookie,
                                error=error)
            else:
                self.redirect('/')
        else:
            self.redirect("/signup")
Example #3
0
    def get(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')
        if user_cookie:
            if user_logged_in(user_cookie):
                self.render("add-comment.html",
                            post_id=post_id,
                            user_cookie=user_cookie)
            else:
                self.redirect('/signup')
        else:
            self.redirect('/signup')
Example #4
0
    def post(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')

        if user_cookie:
            user_id_cookie = user_cookie.split('|')[0]
            if user_owns_post(post_id, user_id_cookie):
                self.delete_post(post_id)
                time.sleep(0.5)
                self.redirect("/")
            else:
                self.redirect("/")
        else:
            self.redirect("/")
Example #5
0
    def get(self, post_id):

        post_exists(post_id)

        user_cookie = self.request.cookies.get('user')
        if user_cookie:
            user_id_cookie = user_cookie.split('|')[0]
            if user_logged_in(user_cookie):
                if user_owns_post(post_id, user_id_cookie):
                    self.render("edit-post.html", posts=[post_exists(post_id)],
                                user_cookie=user_cookie)
                else:
                    self.redirect('/')
            else:
                self.redirect('/')
        else:
            self.redirect('/signup')
Example #6
0
    def post(self, post_id):

        post_exists(post_id)

        comment = self.request.get("comment")
        user_cookie = self.request.cookies.get('user')
        user_id_cookie = user_cookie.split('|')[0]
        if user_logged_in(user_cookie):
            if comment:
                c = Comment(comment=comment,
                            post_id=int(post_id),
                            user_id=int(user_id_cookie))
                c.put()
                time.sleep(0.5)
                self.redirect("/post/%d" % int(post_id))
            else:
                error = "We need a comment!"
                self.render("comment.html",
                            comment=comment,
                            error=error,
                            user_cookie=user_cookie)
        else:
            self.redirect('/')