示例#1
0
    def post(self):

        current_user = self.current_user
        title = self.request.get("title")
        text = self.request.get("content")

        if title and text:
            post = Post(author=current_user, title=title, content=text)
            post.put()
            self.redirect("/post/" + str(post.key().id()))
        else:
            error = "Title and Text must be provided to submit an article!"
            self.render("newpost.html", error=error)
示例#2
0
    def post(self):
        subject = self.get_argument('subject').strip()
        subject_error = get_subject_error(subject)

        content = self.get_argument('content').strip()
        content_error = get_content_error(content)

        if subject_error or content_error:
            self.render(
                subject=subject,
                subject_error=subject_error,
                content=content,
                content_error=content_error
            )

        else:
            blog_post = Post()
            blog_post.subject = subject
            blog_post.content = content
            blog_post.put()
            self.redirect('/{post_id}'.format(post_id=blog_post.key().id()))
示例#3
0
    def post(self):
        """
        Creates or update a new post entry if user is 
        authenticated, if no redirects to login route
        :return: 
        """
        user_id = self.request.cookies.get('user_id')
        post_id = self.request.get('id')
        title = self.request.get('title')
        content = self.request.get('content')

        if 'update' in self.request.POST:
            post = Post.get_by_id(post_id)

            if Post.is_post_owner(user_id, post):
                post.title = title
                post.content = content
                post.last_modified = datetime.datetime.now()

                post.put()

                time.sleep(2)
        elif 'create' in self.request.POST:
            title = self.request.get('title')
            content = self.request.get('content')

            user = User.get_by_hash(user_id)

            p = Post(author=user.user,
                     title=title,
                     content=content,
                     created=datetime.datetime.now(),
                     last_modified=datetime.datetime.now())
            p.put()

            time.sleep(2)

        self.redirect('/main')