async def do_manage_alter(json,opr_type): id=json['id'] if opr_type=='delete': s=await blog_tb.delete(id) if s: return jsonResponse(message='删除成功') return apiError(message='删除失败') if opr_type=='add_category': cate=Category(name=json['name']) s = await man.cate_tb.insert(cate) if s: return jsonResponse(message='操作成功') return apiError(message='操作失败')
async def do_manage_alter(json, opr_type): id = json['id'] if opr_type == 'delete': s = await blman.deleteBlog(id) if s: return jsonResponse(message='删除成功') return apiError(message='删除失败')
async def do_me_delete_blog(blog_id, cookies): chk = await checkRequiredData(bid=blog_id, from_public=False, cookies=cookies) if not chk.success: return chk.errorJsonResponse b = await Blog.find(blog_id) r = await Blog.delete(b.id) if not r: return apiError(message='删除失败') return jsonResponse(message='删除成功')
async def do_editor_post( opr_type,title,text,md,html,description,author,info,category,tags,id, digest,keywords,fields,format_used,mood,status,visible ): # 数据检查和处理 created_at=time.time() b=Blog( title=title,text=text,md=md,format_used=format_used,html=html, created_at=created_at,category=category,tags=tags,id=id,author=author, description=description,info=info,digest=digest,keywords=keywords,fields=fields, mood=mood,status=status,visible=visible ) await man.upsertBlogSafe(b) return jsonResponse(success=True,message='上传成功!')
async def do_editor_post(title, md, html, description, author, info, category, tags, opr_type, id): created_at = time.time() text = md html = tools.textToHTML(text) b = Blog(title=title, text=text, html=html, created_at=created_at, category=category, tags=tags, id=id, author=author) await blman.saveBlog(b) return jsonResponse(success=True, message='上传成功!')
async def create_blog_post(blog_heading, blog_summary, blog_content, is_public, type, label, cookies): chk = await checkRequiredData(from_public=False, cookies=cookies) if not chk.success: return chk.errorJsonResponse uid = cookies['user_id'] u = await User.find(uid) if blog_heading.strip() == '': return apiError(message='文章标题不能为空') b = await Blog.easyBlog(u, name=blog_heading, summary=blog_summary, content=blog_content, public=is_public, type=type, label=label) return jsonResponse(success=True, message='文章上传成功,<a href="/me">前往主页?</a>', data=b)
async def do_comment_post(blog_id, content, cookies): chk = await checkRequiredData(bid=blog_id, from_public=False, cookies=cookies) if not chk.success: return chk.errorJsonResponse user_id = cookies['user_id'] logging.info('cookies:%s' % cookies) u = await User.find(user_id) if content.strip() == '': return apiError(message='评论不能为空!') comment = Comment(user_id=user_id, user_name=u.name, user_image=u.image, blog_id=blog_id, content=content) logging.info('comments-object formed:%s' % comment) await comment.save() await comment.lightInfo() tem = env.get_template(pages['comment_show']) co = tem.render(comment=comment) return jsonResponse(data={'comment': co})
async def do_editor_post(blog_id, blog_heading, blog_summary, blog_content, is_public, type, label, cookies): chk = await checkRequiredData(bid=blog_id, from_public=False, cookies=cookies) if not chk.success: return chk.errorJsonResponse b = await Blog.find(blog_id) u = await User.find(b.user_id) if blog_heading.strip() == '': return apiError(message='文章标题不能为空') if blog_summary.strip() == '': blog_summary = blog_content[:200] if len( blog_content) >= 200 else blog_content r = await b.update(name=blog_heading, summary=blog_summary, content=blog_content, public=is_public, type=type, label=label) if not r: log('failed to update blog %s' % blog_id) return apiError(message='更新失败') return jsonResponse(message='更新成功,<a href="/me">前往主页?</a>')
async def do_get_blog(blog_id): blog=await blog_tb.findByPK(blog_id) if blog: return jsonResponse(data=blog.toJson()) return apiError(message='blog not found.')
async def do_app_post(aname, request): new_html = await request.text() fpath = 'templates/app/' + aname + '/' + 'content.txt' writeFile(fpath, new_html) return jsonResponse(message="提交成功")
async def do_get_blog(blog_id): blog = await blman.getBlogByID(blog_id) if blog: return jsonResponse(data=blog.toJson()) return apiError(message='blog not found.')