Пример #1
0
    def post(self):

        if not self.user:
            self.redirect("/accessdenied")
        else:
            subject = self.request.get("subject")
            content = self.request.get("content").replace('\n', '<br>')
            user_id = User.by_name(self.user.name)
            username = self.user.name

            if subject and content:
                a = Blog(parent=blog_key(),
                         subject=subject,
                         content=content,
                         user=user_id)
                a.put()
                self.redirect('/post/%s' % str(a.key().id()))

            else:
                post_error = "Enter subject and content, please"
                self.render("newpost.html",
                            subject=subject,
                            content=content,
                            post_error=post_error,
                            username=username)
    def post(self):
        if self.user:
            # get the subject, content of the post and username of the user
            subject = self.request.get("subject")
            content = self.request.get("content").replace('\n', '<br>')
            user_id = User.by_name(self.user.name)
            # if we have a subject and content of the post add it to the
            # database and redirect us to the post page
            if subject and content:
                a = Blog(parent=blog_key(),
                         subject=subject,
                         content=content,
                         user=user_id)
                a.put()
                return self.redirect('/post/%s' % str(a.key().id()))

            # othersie throw and error to let the user know that both subject
            # and content are required
            else:
                post_error = "Please enter a subject and the blog content"
                self.render("newpost.html",
                            subject=subject,
                            content=content,
                            post_error=post_error)
        else:
            self.redirect("/login")
Пример #3
0
 def new_post(self, subject, body, user):
     '''Creates a new post and stores to Blog database'''
     post = Blog(subject=subject, body=body, user=user, likes=0)
     post.put()
     redirect = '/blog/pl/%s' % str(post.key().id())
     return redirect