示例#1
0
    def post(self, post_id):
        if self.user:
            if 'main' in self.request.POST:
                self.redirect('/blog')
            elif 'sub' in self.request.POST:
                # get inputs
                subject = self.request.get('subject')
                content = self.request.get('content')
                article = Article.by_id(post_id)
                uid = self.read_secure_cookie('user_id')

                if article.created_by == uid:

                    if subject and content:
                        article.title = subject
                        article.text = content
                        article.put()
                        self.redirect('/blog/%s' % str(article.key().id()))
                    else:
                        # error check if either one is empty
                        error = "Subject or Content is missing"
                        self.render("edit_post.html",
                                    title=subject,
                                    text=content,
                                    error=error)
                else:
                    self.redirect('/blog/broken')
        else:
            self.redirect('/blog/login')
            return
示例#2
0
    def get(self, post_id):
        if self.user:
            article = Article.by_id(post_id)

            # checking if the article has the user on the who-liked list
            uid = self.read_secure_cookie('user_id')

            #if the author likes their own post,
            article_uid = article.created_by
            if article_uid == uid:
                #throw an error
                self.redirect('/blog/like_by_author')
                return

            if uid in article.who_liked:
                # user can't fall into this if clause since use won't see the like button
                self.redirect('/blog/broken')
                return
            else:
                # add uid to who_liked array
                article.who_liked.append(uid)
                article.likes = article.likes + 1
                article.put()
                self.render('liked.html', user=self.user)
        else:
            self.error = "You have to login to like the post"
            self.redirect("/blog/login")
示例#3
0
    def post(self, post_id):
        if self.user:
            article = Article.by_id(post_id)
            uid = self.read_secure_cookie('user_id')

            if article.created_by == uid:
                self.render('/blog')
            else:
                self.redirect('/blog/broken')
        else:
            self.redirect('/blog/login')
示例#4
0
    def get(self, post_id):
        if self.user:
            article = Article.by_id(post_id)
            uid = self.read_secure_cookie('user_id')

            if article.created_by == uid:
                self.render("delete_confirmation.html")
            else:
                self.redirect('/blog/broken')
        else:
            self.redirect('/blog/login')
示例#5
0
 def get(self, post_id):
     if self.user:
         # get post
         article = Article.by_id(post_id)
         if not article:
             self.redirect('/blog/broken')
             return
         # render post
         self.render("new_comment.html",
                     title=article.title,
                     user=self.user)
     else:
         self.error = "You have to login to see the post"
         self.redirect("/blog/login")
示例#6
0
    def get(self, post_id):
        if self.user:
            article = Article.by_id(post_id)
            if not article:
                self.redirect('/blog/broken')
                return

            self.render("permalink.html",
                        article=article,
                        name=self.user.name,
                        user=self.user)
        else:
            self.error = "You have to login to see the post"
            self.redirect("/blog/login")
示例#7
0
    def post(self, post_id):
        if self.user:
            if 'back_2_main' in self.request.POST:
                self.redirect('/blog')
            elif 'delete_post' in self.request.POST:
                article = Article.by_id(post_id)
                uid = self.read_secure_cookie('user_id')

                if article.created_by == uid:
                    perma_link = article.key().id()
                    article.delete()
                    self.redirect("/blog/%s/delete_confirmation" %
                                  (perma_link))
                else:
                    self.redirect('/blog/broken')
                    return
        else:
            self.redirect('/blog/login')
            return
示例#8
0
    def get(self, post_id):
        if self.user:
            article = Article.by_id(post_id)

            if not article:
                self.redirect('/blog/broken')
                return

            uid = self.read_secure_cookie('user_id')

            if article.created_by == uid:
                # send it to edit_post page.
                self.render("delete_post.html",
                            article=article,
                            user=self.user)
            else:
                self.redirect('/blog/broken')
                return
        else:
            self.redirect('/blog/login')
            return
示例#9
0
    def get(self, post_id):
        if self.user:
            article = Article.by_id(post_id)
            uid = self.read_secure_cookie('user_id')

            #if the author dislike their own post,
            article_uid = article.created_by
            if article_uid == uid:
                #throw an error
                self.redirect('/blog/like_by_author')
                return
            if uid in article.who_liked:
                # delete uid from who_liked array
                article.who_liked.remove(uid)
                article.likes -= 1
                article.put()
                self.render('disliked.html', user=self.user)
            else:
                self.redirect('/blog/broken')
                return
        else:
            self.redirect('/blog/broken')
示例#10
0
    def get(self, post_id):
        if self.user:
            article = Article.by_id(post_id)

            if not article:
                self.redirect('/blog/broken')
                return

            # prevent anonymous logged in user from accessing edit
            # post by url:/blog/98792739/edit
            uid = self.read_secure_cookie('user_id')

            if article.created_by == uid:
                # send it to edit_post page.
                self.render("edit_post.html",
                            text=article.text,
                            title=article.title,
                            user=self.user)
            else:
                self.redirect('/blog/broken')
                return
        else:
            self.redirect('/blog/login')
            return