async def api_create_comment(id, request, *, content): user = request.__user__ if user is None: raise APIPermissionError('Please signin first.') if not content or not content.strip(): raise APIValueError('content') blog = await Blog.find(id) blog_user = await User.find(blog.user_id) send_email.send_comment_email(blog_user.email, content, '/blog/%s' % id) if blog is None: raise APIResourceNotFoundError('Blog') comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip()) await comment.save() return comment
async def api_create_reply(request, *, blog_id, comment_id, content, reply_user_id): user = request.__user__ if user is None: raise APIPermissionError('请先登录哦!(Please signin first.)') if not content or not content.strip(): raise APIValueError('content') reply_user = await User.find(reply_user_id) if reply_user is None: raise APIPermissionError('您回复的账号不存在!') send_email.send_comment_email(reply_user.email, content, '/blog/%s' % blog_id) reply = Reply(comment_id=comment_id, user_id=user.id, reply_user_id=reply_user_id, user_name=user.name, user_image=user.image, content=content) await reply.save() return reply
# def application(environ, start_response): # start_response('200 OK', [('Content-Type', 'text/html')]) # print(environ) # body = '<h1>Hello, %s!</h1>' % (environ['PATH_INFO'][1:] or 'web') # return [body.encode('utf-8')] # # # from wsgiref.simple_server import make_server # # httpd = make_server('', 8000, application) # print('Serving Http on port 8000..') # httpd.serve_forever() import send_email send_email.send_comment_email( '*****@*****.**', '一条留言', "/blog/0015279355359080a648f9223784255ba6199a8892e44c0000")