def get(self,blog_id): user=self.check_login() if user=="guest" or user==None: self.redirect("/blog/login") original_post=Message.get_by_id(int(blog_id)) if not original_post: return self.error(404) self.render("newcomment.html", user=user, original_post=original_post)
def post(self): user=self.check_login() if user=="guest" or user==None: self.redirect("/blog/login") return error="" #delete comment Delete_c = self.request.get_all("delete_c") for delete in Delete_c: entity=Comment.get_by_id(int(delete)) if not entity: error="Error: No comment to be deleted!" elif user==entity.commenter: entity.delete() else: error="Error: You can't delete others' post!" #delete blog Delete = self.request.get_all("delete") for delete in Delete: entity=Message.get_by_id(int(delete)) if not entity: error="Error: No blog to be deleted!" elif user==entity.author: entity.delete() else: error="Error: You can't delete others' post!" #like blog Like= self.request.get_all("like") for like in Like: entity=Message.get_by_id(int(like)) if user==entity.author: error="Error: You can't like your own post!" else: entity.like(user) messages=db.GqlQuery("SELECT * FROM Message ORDER BY created DESC LIMIT 10") comments={} for message in messages: q=message.key().id() comment=db.GqlQuery("SELECT * FROM Comment WHERE blog_id = '%s' ORDER BY created DESC"%q) comments[q]=comment self.render("result.html", user = user, messages=messages, comments=comments, error=error, pytz=pytz)
def post(self,blog_id): user=self.check_login() if user=="guest" or user==None: self.redirect("/blog/login") original_post=Message.get_by_id(int(blog_id)) if not original_post: return self.error(404) old_text=self.request.get("text") if old_text: new_comment=Comment(blog_id=blog_id, commenter=user, text=old_text) new_comment.put() self.redirect("/blog/"+blog_id) self.render("newcomment.html", user=user, original_post=original_post, text=old_text, error="Please give a comment!")
def get(self, comment_id): user = self.check_login() if user == "guest" or user == None: self.redirect("/blog/login") comment = Comment.get_by_id(int(comment_id)) if not comment: return self.error(404) if user != comment.commenter: self.redirect("/blog") else: old_text = comment.text original_post = Message.get_by_id(int(comment.blog_id)) self.render("editcomment.html", user=user, original_post=original_post, old_text=old_text, error="")
def post(self, blog_id): user = self.check_login() if user == "guest" or user == None: self.redirect("/blog/login") result = Message.get_by_id(int(blog_id)) if not result: return self.error(404) comments = db.GqlQuery( "SELECT * FROM Comment WHERE blog_id='%s' ORDER BY created DESC" % blog_id) new_like = self.request.get("like") if new_like: result.like(new_like) self.render("result2.html", user=user, messages=result, comments=comments)
def get(self, blog_id): user = self.check_login() if user == "guest" or user == None: self.redirect("/blog/login") return blogs = Message.get_by_id(int(blog_id)) if not blogs: return self.error(404) if user != blogs.author: self.redirect("/blog") else: title = blogs.title text = blogs.text self.render("editblog.html", user=user, old_title=title, old_text=text, error="")
def get(self, blog_id): user = self.check_login() #if user=="guest" or user==None: # self.redirect("/blog/login") #self.init_comment() comment = db.GqlQuery( "SELECT * FROM Comment WHERE blog_id='%s' ORDER BY created DESC" % blog_id) q_i = int(blog_id) comments = {} comments[q_i] = comment result = Message.get_by_id(int(blog_id)) if not result: return self.error(404) self.render("result2.html", user=user, messages=result, comments=comments)
def post(self, comment_id): #edit comment user = self.check_login() if user == "guest" or user == None: self.redirect("/blog/login") comment = Comment.get_by_id(int(comment_id)) if not comment: return self.error(404) if user != comment.commenter: self.redirect("/blog") text = self.request.get("text") blog_id = comment.blog_id original_post = Message.get_by_id(int(comment.blog_id)) if text == "": error = "Please input some word to modify!" self.render("editcomment.html", original_post=original_post, user=user, old_text=text, error=error) else: comment.modify(text=text) self.redirect("/blog/" + blog_id)
def post(self, blog_id): #edit blog user = self.check_login() if user == "guest" or user == None: self.redirect("/blog/login") return entity = Message.get_by_id(int(blog_id)) if not entity: return self.error(404) if user != entity.author: self.redirect("/blog") title = self.request.get("title") text = self.request.get("text") if title == "" or text == "": error = "Please input some word to modify!" self.render("editblog.html", user=user, old_title=title, old_text=text, error=error) else: entity.modify(title=title, text=text) self.redirect("/blog/" + blog_id)