def post(self, postId): post = Post.get_post_by_id(postId) if not post or post.status != 0 or post.commentstatus == 1: self.write('抱歉,评论功能已关闭。') else: username = self.get_argument('username', '') email = self.get_argument('email', '') content = self.get_argument('comment', '') parentid = int(self.get_argument('parentid', 0)) if self.islogin: curr_user_info = self.get_current_user_info username = curr_user_info.username email = curr_user_info.email if username == '' or content == '' or not isemail(email): self.flash(u'错误:称呼、电子邮件与内容是必填项') self.redirect(post.url + '#comments') return username = username[:20] content = content[:512] if not self.islogin: is_spam = spam_check(content, self.request.remote_ip) else: is_spam = 0 if is_spam: self.flash(u'sorry,your comment is not posted') self.redirect(post.url+'#comments') location = get_location_byip(self.request.remote_ip) Comment.post_comment(postid=postId, username=username, email=email, content=content, parentid=parentid, ip=self.request.remote_ip, isspam=is_spam, location=location) if is_spam: self.flash(u'您的评论可能会被认定为Spam') self.set_comment_user(username, email) self.redirect(post.url + '#comments')
def get(self, id): post = Post.get_post_by_id(id, ignorestatus=True) self.datamap['category'] = Category.get_categorys() self.datamap['tags'] = Tag.get_tags() self.datamap['post'] = post self.datamap['chose_tag'] = [x.tag for x in post.tag] self.datamap['chose_category'] = [x.category for x in post.category] self.write(render_admin.editpost(self.datamap))
def post(self, id): post = Post.get_post_by_id(id) if not post: self.set_error(404) if post.password.strip() != "": password = self.get_argument('password', '') if password == post.password: self.set_secure_cookie('post_' + str(id), password, expires_days=1) else: self.flash(u'验证密码不正确') self.redirect('/post/' + str(id) + '/')
def get(self, postId): post = None act = self.get_argument('act', '') if act == 'del_comment' and self.islogin: cid = self.get_argument('cid', 0) Comment.delete_comment_by_id(cid) self.add_header('content-type', 'application/json;charset=utf-8') self.write(json.dumps({'code': 0, 'msg': 'OK'})) return if isint(postId): post = Post.get_post_by_id(postId, ignorestatus=True) else: post = Post.get_post_by_alias(postId, ignorestatus=True) if not post or post.status != 0: self.set_error(404) act = self.get_argument('act', '') if act == 'clear': self.set_secure_cookie('post_' + str(postId), '', expires_days=-10) self.datamap['valid'] = True if post.password.strip() != "": if self.get_secure_cookie('post_' + str(postId)) != post.password: self.datamap['valid'] = False if act and self.islogin: if act == 'delete': Post.delete_post_by_id(postId) self.redirect('/') return elif act == 'edit': self.redirect('/admin/?url=/admin/post/edit/%s/' % post.id) return self.datamap['post'] = post self.datamap['recent'] = Post.get_recent_post() comment = Comment.get_comments_by_postid(post.id, isAdmin=self.islogin) self.datamap['commentcount'] = comment[0] self.datamap['comments'] = comment[1] if self.islogin: self.datamap['curr_user_info'] = self.get_current_user_info self.write(render.post(self.datamap))