本文整理汇总了Python中models.Blog.find方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.find方法的具体用法?Python Blog.find怎么用?Python Blog.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Blog
的用法示例。
在下文中一共展示了Blog.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(request, *, id):
check_admin(request)
# 根据model类的定义,只有查询才是类方法,其他删改都是实例方法
# 所以要先创建一个实例
blog = yield from Blog.find(id)
yield from blog.remove()
return dict(id=id) # 返回被删除博客的id
示例2: get_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def get_blog(id):
blog = yield from Blog.find(id)
comments = yield from Comment.findAll("blog_id=?", [id], orderBy="created_at desc")
for c in comments:
c.html_content = text2html(c.content)
blog.html_content = markdown2.markdown(blog.content).replace("\n", "</br>")
return {"__template__": "blog.html", "blog": blog, "comments": comments}
示例3: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(request, *, id):
check_admin(request) # 检查用户权限
# 根据model类的定义,只有查询才是类方法,其他增删改都是实例方法
# 因此需要先创建对象,再删除
blog = yield from Blog.find(id) # 取出博客
yield from blog.remove() # 删除博客
return dict(id=id) # 返回被删博客的id
示例4: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(request, *, id):
check_admin(request)
blog = yield from Blog.find(id)
if blog is None:
raise APIResourceNotFoundError('blog not found')
yield from blog.delete()
return dict(id=id)
示例5: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(request, *, id):
check_admin(request)
blog = yield from Blog.find(id)
if blog is None:
return APIResourceNotFoundError('Blog')
yield from blog.remove()
return dict(id=id)
示例6: get_api_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def get_api_blog(id):
blog=yield from Blog.find(id)
if blog:
return blog
else:
raise APIValueError('id','wrong id')
return None
示例7: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(id, request):
logger.info("删除博客的博客ID为:%s" % id)
check_admin(request)
b = yield from Blog.find(id)
if b is None:
raise APIResourceNotFoundError('Comment')
yield from b.remove()
return dict(id=id)
示例8: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(request, *, id):
check_admin(request)
blog = yield from Blog.find(id)
yield from blog.remove()
comments = yield from Comment.find_all('blog_id=?', [id])
for c in comments:
yield from c.remove()
return dict(id=id)
示例9: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(id, request):
logging.info('delete a blog %s', id)
check_admin(request)
blog = yield from Blog.find(id)
if blog is None:
raise APIResourceNotFoundError('blog not found')
yield from blog.remove()
raise dict(id=id)
示例10: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(id, request):
check_admin(request)
blog = yield from Blog.find(id)
comments = yield from Comment.findAll(where="blog_id='%s'" % id)
yield from blog.remove()
for comment in comments:
yield from comment.remove()
return dict(id=id)
示例11: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(request, *, id):
# 校验当前用户权限:
check_admin(request)
# 数据库Blog表中查询指定文章信息:
blog = yield from Blog.find(id)
# 将Blog信息从数据库删除:
yield from blog.remove()
return dict(id=id)
示例12: api_delete_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def api_delete_blog(request, *, id):
'''
删除日志
'''
check_admin(request)
blog = yield from Blog.find(id)
yield from blog.remove()
return dict(id=id)
示例13: get_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def get_blog(id):
# 通过id在数据库Blog表中查询对应内容:
blog = yield from Blog.find(id)
# 通过id在数据库Comment表中查询对应内容:
comments = yield from Comment.findAll("blog_id=?", [id], orderBy="created_at desc")
for c in comments:
# 将content值从text格式转换成html格式:
c.html_content = text2html(c.content)
blog.html_content = markdown2.markdown(blog.content)
return {"__template__": "blog.html", "blog": blog, "comments": comments}
示例14: create_comment
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def create_comment(*, blog_id, content):
if not content or not content.strip():
raise APIValueError('content', 'content cannot be empty')
#get blog
blog = yield from Blog.find(blog_id)
comment = Comment(user_id=blog.user_id, user_name=blog.user_name, user_image=blog.user_image,
blog_id=blog_id, content=content)
yield from comment.save()
return comment
示例15: get_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import find [as 别名]
def get_blog(id):
blog = yield from Blog.find(id)
comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
for c in comments:
c.html_content = text2html(c.content)
blog.html_content = markdown2.markdown(blog.content)
return {
'__template__': 'blog.html',
'blog': blog,
'comments': comments
}