Example #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")
Example #3
0
def add_blog():
    if not current_user.is_admin:
        return {'success': False, 'err': 'No permissions'}

    req_data = request.get_json()

    if not ('uid' in req_data and 'name' in req_data and 'author' in req_data
            and 'date' in req_data and 'content' in req_data):
        return {'success': False, 'err': 'Invalid request body'}

    new_blog = Blog(_uid=req_data['uid'],
                    _name=req_data['name'],
                    _author=req_data['author'],
                    _date=req_data['date'],
                    _content=req_data['content'])
    new_blog.put()

    return {'success': True}
Example #4
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