def delete_comment(self, comment_id=None, submit=None): if cherrypy.request.method.lower() != "post": error("Cannot service non-post requests.") author = get_author() if author is None: error("You need to be logged in to delete comments.") comment = db.get_comment(comment_id) if comment is None: error("Invalid comment id.") post = db.get_post(comment["post_id"]) if post["author_id"] == author["id"]: if not db.del_comment(comment_id): error("Failed to delete comment.") raise cherrypy.HTTPRedirect("/entry/%s" % post["id"])
def post(self, page): # 校验身份 if self.check_login() == False: self.redirect("/login") return m = self.get_argument("m", "none") # 添加文章 if m == "add_article": title = self.get_argument("title", "") content = self.get_argument("content", "") classify = self.get_argument("classify", "") if title == "" or content == "" or classify == "": self.redirect("/login") return db.add_article(title, content, classify) self.redirect("/admin/%s" % page) # 删除文章 elif m == "del_article": id = self.get_argument("id", "") if id == "": self.redirect("/login") return db.del_article(id) self.redirect("/admin/%s" % page) # 修改文章 elif m == "update_article": id = self.get_argument("id", "") title = self.get_argument("title", "") content = self.get_argument("content", "") if id == "" or title == "" or content == "": self.redirect("/login") return db.update_article(id, title, content) self.redirect("/admin/%s" % page) # 删除评论 elif m == "del_comments": id = self.get_argument("id", "") if id == "": self.redirect("/login") return db.del_comment(id) self.redirect("/admin/%s" % page) # 删除留言 elif m == "del_guests": id = self.get_argument("id", "") if id == "": self.redirect("/login") return db.del_guest(id) self.redirect("/admin/%s" % page) # 添加链接 elif m == "add_links": url = self.get_argument("url", "") title = self.get_argument("title", "") if url == "" or title == "": self.redirect("/login") return db.add_link(title, url) self.redirect("/admin/%s" % page) # 删除链接 elif m == "del_links": id = self.get_argument("id", "") if id == "": self.redirect("/login") return db.del_link(id) self.redirect("/admin/%s" % page) # 添加分类 elif m == "add_classify": name = self.get_argument("name", "") if name == "": self.redirect("/login") return db.add_classify(name) print page self.redirect("/admin/%s" % page) # 删除链接 elif m == "del_classify": id = self.get_argument("id", "") if id == "": self.redirect("/login") return db.del_classify(id) self.redirect("/admin/%s" % page) # 更新配置 elif m == "update_options": map = {} map["blogname"] = self.get_argument("blogname", "") map["nickname"] = self.get_argument("nickname", "") map["email"] = self.get_argument("email", "") map["descript"] = self.get_argument("descript", "") map["pagecount"] = self.get_argument("pagecount", "") map["timeout"] = self.get_argument("timeout", "") config.update(map) self.redirect("/admin/%s" % page) # 获取最近上传文件 elif m == "get_upload": files = get_upload(10) self.write(json.dumps(files)) # 获取最近上传文件 elif m == "del_upload": filename = self.get_argument("filename") del_upload(filename) else: self.redirect("/login")