def api_modify_blog(blog_id): check_admin() blog = Blogs.get(blog_id) if not blog: raise APIValueError(blog_id, 'blog is not exist.') i= ctx.request.input(title='', tags='', content='') title = i['title'].strip() tags = i['tags'].strip() content = i['content'].strip() if not title: raise APIValueError('title', 'title can not be empty.') if not content: raise APIValueError('content', 'content can not be empty.') summary = _get_summary(content) blog.title = title blog.summary = summary blog.content = content blog.tags = tags blog.update() db.execute('delete from `tags` where `blog`=?', blog_id) if tags: for tag in tags.split(','): tag = Tags(tag=tag, blog=blog_id) tag.insert() return dict(id=blog_id)
def api_create_blog(): check_admin() i= ctx.request.input(title='', tags='', content='') title = i['title'].strip() tags = i['tags'].strip() content = i['content'].strip() if not title: raise APIValueError('title', 'title can not be empty.') if not content: raise APIValueError('content', 'content can not be empty.') summary = _get_summary(content) blog = Blogs(title=title, tags=tags, summary=summary, content=content) id = blog.insert_id() if tags: for tag in tags.split(','): tag = Tags(tag=tag, blog=id) tag.insert() return dict(id=id)