def post(self): """ To process ans store blog post information into database """ title = self.request.get("title") content = self.request.get("content") if self.user: if title and content: user_obj = User.get_by_id(int(self.user)) # adding publish date directly for now post = Post(title=title, content=content, user=user_obj, published_at=datetime.now()) new_post = post.put() self.redirect("/blog/{}".format(db.get(new_post).slug)) else: error = "Both title and art required for submitting !" self.render("add_blog.html", subject=title, content=content, error=error) else: cookie_error = "Your session has expired please login again to continue!" self.render('login.html', error=cookie_error)
def post(self): subject = self.request.get('subject') content = self.request.get('content').replace('\n', '<br>') if subject and content: p = Post(subject=subject, content=content) p.put() post_id = str(p.key().id()) self.redirect('/blog/%s/' % post_id) else: error = "Please add both a title and a post!" self.render_newpost(subject, content, error)
def post(self, post_id): """ To process ans store blog post information into database """ title = self.request.get("title") content = self.request.get("content") if self.user: post = Post.get_by_id(int(post_id)) if post.user.key().id() == int(self.user): if title and content: post.title = title post.content = content # post.slug = post.slug # TODO: should we change slug or not? else permalink wont be perament! Dig on how to fix this new_post = post.put() self.redirect("/blog/{}".format(db.get(new_post).slug)) else: error = "Both title and art required for submitting !" self.render("edit_blog.html", post=post, error=error) else: error = "You cannot edit this post." self.render("edit_blog.html", access_error=error) else: self.login_redirect()
def get(self, post_id): post = Post.get_by_id(int(post_id)) if not post: self.error(404) return self.render('permalink.html', post=post)
def get(self, post_slug): is_author = False post = Post.all().filter("slug =", post_slug).get() if not post: self.error(404) return if self.user and post.user.key().id() == int(self.user): is_author = True self.render('permalink.html', post=post, is_author=is_author)
def get(self, post_slug): is_author=False post = Post.all().filter("slug =", post_slug).get() if not post: self.error(404) return if self.user and post.user.key().id() == int(self.user): is_author = True self.render('permalink.html', post=post, is_author=is_author)
def post(self, post_id): """ Create a new comment for the post with post_id as in params """ if not self.user: error = "You must be logged in to comment" self.render('login.html', error=error) else: post = Post.get_by_id(int(post_id)) user_obj = User.get_by_id(int(self.user)) comment = self.request.get('comment') comment = Comment(comment=comment, user=user_obj, post=post) comment.put() self.redirect("/blog/{}".format(post.slug))
def get(self, post_id): """ Renders the form for adding post """ if self.user: post = Post.get_by_id(int(post_id)) if not post: self.error(404) if post.user.key().id() == int(self.user): self.render("edit_blog.html", post=post) else: error = "You cannot edit this post." self.render("edit_blog.html", access_error=error) else: cookie_error = "Your session has expired please login again to continue!" self.render('login.html', error=cookie_error)
def get(self, post_id): """ """ user_obj = User.get_by_id(int(self.user)) if not self.user: cookie_error = "Your session has expired please login again to continue!" self.render('login.html', error=cookie_error) else: post = Post.get_by_id(int(post_id)) author = post.user.key().id() if author == int(self.user) or Like.all().filter('post =', post).filter('user ='******'/like/error') else: like = Like(post=post, user=user_obj) like.put() self.redirect("/blog/{}".format(post.slug))
def get(self, post_id): """ To delete a blog post, Can be done by only user who created it """ if self.user: post = Post.get_by_id(int(post_id)) if not post: self.error(404) if post.user.key().id() == int(self.user): post.delete() self.redirect('/') else: error = "You cannot delete this post." self.render("edit_blog.html", access_error=error) else: cookie_error = "Your session has expired please login again to continue!" self.render('login.html', error=cookie_error)