def post(self, post_id): self.p = BlogInfo.get_by_id(int(post_id)) self.post_comments = Comment.all().ancestor(self.p).fetch(limit=10) self.like_status = Likes.all().ancestor(self.p).get() self.comment_author = self.get_user() self.comment_text = self.request.get("comment") params = dict(p = self.p, post_comments = self.post_comments, like_status = self.like_status, this_user = self.comment_author) if self.comment_text and self.comment_author: comment = Comment(comment_text = self.comment_text, comment_author = self.comment_author, associated_post = int(post_id), like_status = self.like_status, parent=self.p) comment.put() self.redirect("/blog/%s" % post_id) elif self.comment_author and not self.comment_text: params.update(main.loggedin_params) params["no_comment"] = "Please enter text" self.render("permalink.html", **params) else: params.update(main.loggedout_params) params["cant_comment"] = "Please log in to comment" self.render("permalink.html", **params)
def post(self, post_id, c_id): self.comment_text = self.request.get("comment") self.p = BlogInfo.get_by_id(int(post_id)) self.comm = Comment.get_by_id(int(c_id), parent=self.p) self.post_comments = Comment.all().ancestor(self.p).fetch(limit=10) self.this_user = self.get_user() params = dict(comment_to_edit = self.comm, this_user = self.this_user, post_comments = self.post_comments) if not self.this_user: self.redirect('/login') if self.this_user == self.comm.comment_author: if not self.comment_text: params.update(main.loggedin_params) params["error"] = "Need content to post comment." self.render("editcomment.html", **params) else: self.comm = Comment.get_by_id(int(c_id), parent= self.p) self.comm.comment_text = self.comment_text self.comm.put() self.redirect("/blog/%s" % self.comm.associated_post) else: params.update(main.loggedin_params) params["error"] = "You may only edit your own comments." self.render("editcomment.html", **params)
def get(self, post_id): self.this_user = self.get_user() self.p = BlogInfo.get_by_id(int(post_id)) if self.this_user: if self.p and self.this_user == self.p.author: self.title = self.p.title self.p.delete() self.render("deleted.html", title = self.title) else: self.redirect('/blog') else: self.redirect('/login')
def get(self): self.blogposts = BlogInfo.all().order('-created') self.this_user = self.get_user() params = dict(blogposts=self.blogposts, this_user=self.this_user) if self.this_user: params.update(main.loggedin_params) self.render("blog.html", **params) else: params.update(main.loggedout_params) self.render("blog.html", **params)
def get(self, post_id, c_id): self.p = BlogInfo.get_by_id(int(post_id)) self.comm = Comment.get_by_id(int(c_id), parent=self.p) self.this_user = self.get_user() if self.this_user: if self.comm and self.comm.comment_author == self.this_user: self.comm.delete() self.redirect("/blog/%s" % post_id) else: self.redirect('/blog') else: self.redirect('/login')
def get(self, post_id, is_liked): self.p = BlogInfo.get_by_id(int(post_id)) self.this_user = self.get_user() self.like_status = Likes.all().ancestor(self.p).get() self.post_comments = Comment.all().ancestor(self.p).fetch(limit=10) params = dict(p = self.p, this_user = self.this_user, like_status = self.like_status, post_comments = self.post_comments) if self.this_user in self.like_status.who_rated: params["like_error"] = "You've already rated this post" params.update(main.loggedin_params) self.render("rate_error.html", **params) elif self.this_user and self.p.author != self.this_user: is_liked = int(is_liked) if is_liked == 0: self.like_status.likes_value += 1 self.like_status.who_rated += [self.this_user] self.like_status.put() self.redirect("/blog/%s" % post_id) else: self.like_status.dislikes_value += 1 self.like_status.who_rated += [self.this_user] self.like_status.put() self.redirect("/blog/%s" % post_id) elif self.p.author == self.this_user: params["like_error"] = "Not allowed to like and dislike own posts" params.update(main.loggedin_params) self.render("rate_error.html", **params) else: params["cant_like"] = "Please login to like and dislike posts" params.update(main.loggedout_params) self.render("rate_error.html", **params)
def get(self, post_id): self.this_user = self.get_user() self.p = BlogInfo.get_by_id(int(post_id)) params = dict(this_user=self.this_user, p=self.p) if self.this_user: if self.p and self.this_user == self.p.author: params.update(main.loggedin_params) self.render("edit.html", **params) else: self.redirect('/blog') else: self.redirect('/login')
def get(self, post_id, c_id): self.p = BlogInfo.get_by_id(int(post_id)) self.comm = Comment.get_by_id(int(c_id), parent=self.p) self.post_comments = Comment.all().ancestor(self.p).fetch(limit=10) self.this_user = self.get_user() params = dict (comment_to_edit = self.comm, this_user = self.this_user, post_comments = self.post_comments) if self.this_user: if self.comm and self.comm.comment_author == self.this_user: params.update(main.loggedin_params) self.render("editcomment.html", **params) else: self.redirect('/blog') else: self.redirect('/login')
def get(self, post_id): self.p = BlogInfo.get_by_id(int(post_id)) self.post_comments = Comment.all().ancestor(self.p).fetch(limit=10) self.like_status = Likes.all().ancestor(self.p).get() self.this_user = self.get_user() params = dict(p = self.p, post_comments = self.post_comments, like_status = self.like_status, this_user = self.this_user) if self.this_user: params.update(main.loggedin_params) self.render("permalink.html", **params) else: params.update(main.loggedout_params) self.render("permalink.html", **params) if not self.p: self.error(404) return
def post(self, post_id): self.title = self.request.get("title") self.content = self.request.get("content") self.p = BlogInfo.get_by_id(int(post_id)) params = dict(title=self.title, content=self.content, p=self.p) if self.this_user == self.p.author: if self.title and self.content: self.p.title = self.title self.p.content = self.content self.p.put() self.redirect("/blog/%s" % post_id) else: params.update(main.loggedin_params) params["error"] = "Please provide the content and the title" self.render("edit.html", **params) else: params.update(main.loggedin_params) params["error"] = "You may only edit your own posts" self.render("edit.html", **params)
def post(self): self.title = self.request.get("title") self.content = self.request.get("content") self.author = self.get_user() params = dict(title = self.title, content=self.content, this_user = self.author) if self.author and self.title and self.content: blogpost = BlogInfo(content = self.content, title = self.title, author = self.author) blogpost.put() likes_value = 0 dislikes_value = 0 who_rated = [] associated_post = blogpost.key().id() like_status = Likes(likes_value = likes_value, dislikes_value = dislikes_value, associated_post = associated_post, who_rated = who_rated, parent = blogpost) like_status.put() self.redirect("/blog/%s" % str(blogpost.key().id())) elif self.author and not (self.title and self.content): params.update(main.loggedin_params) params["error"] = "Please provide the content and the title" self.render("new_post.html", **params) else: params.update(main.loggedout_params) params["error"] = "Please log in to make a post" self.render("new_post.html", **params)