def post(self): pdict = self.request.POST try: #def new(cls, title, category_keyname, author_keyname, url, keyword, tags, content, status=PostStatus.NORMAL, format=PostFormat.PLAIN, enablecomment=True): tags = pdict.get("post.tags").split(",") for i in tags: Tag.Incr(i) pkey = Post.new(title=pdict.get("post.title"), category_keyname=pdict.get("post.category").decode(config.CHARSET).encode("utf-8"), author_keyname=self.session.get("curr_ukey").decode(config.CHARSET).encode("utf-8"), url=pdict.get("post.url"), keyword=pdict.get("post.keyword").split(","), tags=tags, content=pdict.get("post.content"), format=pdict.get("post.format") ) p = Post.id(pkey.id()) p.realurl = realurl(p) Post.put(p) Post.refresh_total() except Exception, ex: context = {} context.update(self.request.POST) context["errors_msg"] = ex context["page_name"] = u"添加文章" context["page_title"] = u"添加文章" context["all_category"] = Category.get_all() self.render("admin_post_editor.html", context)
def post(self, post_id): post_id = int(post_id) post = Post.id(post_id) if not post: #TODO 404 return pdict = self.request.POST nickname = pdict.get("author") email = pdict.get("email") website = pdict.get("url") comment = pdict.get("comment") logging.info(website) #def new(cls, belong, nickname, email, author=None, re=None, ip=None, website=None, hascheck=True, commenttype=CommentType.COMMENT): try: c = Comment.new(belong=post, nickname=nickname, email=email, website=website, content=comment, ip=self.request.client_ip) except Exception, ex: logging.info(traceback.format_exc())
def post(self, post_id): logging.info(self.request.environ) post_id = int(post_id) p = Post.id(post_id) if not p: self.redirect(config.BLOG_ADMIN_PATH + "post/") return pdict = self.request.POST cur_tags = set(pdict.get("post.tags").split(",")) old_tags = set(p.tags) for i in old_tags^(cur_tags&old_tags): Tag.Decr(i) for i in cur_tags^(cur_tags&old_tags): Tag.Incr(i) tags = list(cur_tags) try: old_realurl = p.realurl pkey = Post.modify(post_id=post_id, title=pdict.get("post.title"), category_keyname=pdict.get("post.category").decode(config.CHARSET).encode("utf-8"), author_keyname=self.session.get("curr_ukey").decode(config.CHARSET).encode("utf-8"), url=pdict.get("post.url"), keyword=pdict.get("post.keyword").split(","), tags=pdict.get("post.tags").split(","),#tags, content=pdict.get("post.content"), format=pdict.get("post.format") ) p = Post.id(pkey.id()) if p.realurl != old_realurl: p.realurl = realurl(p) p.put() except Exception, ex: logging.info(ex) context = {} context.update(self.request.POST) context["errors_msg"] = ex context["page_name"] = u"修改文章" context["page_title"] = u"修改文章" context["all_category"] = Category.get_all() self.render("admin_post_editor.html", context)