本文整理汇总了Python中models.Category.findAll方法的典型用法代码示例。如果您正苦于以下问题:Python Category.findAll方法的具体用法?Python Category.findAll怎么用?Python Category.findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.findAll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_blogs_in_catgory
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import findAll [as 别名]
def get_blogs_in_catgory(*, page='1', id):
page_index = get_page_index(page)
try:
num = (yield from calcu_relation_num(int(id), hide_ignore = True))
except ValueError as e:
logging.info('ValueError:', e)
return 'redirect:/'
finally:
pass
page = Page(num, page_index)
blogs_in_catgory = []
if num == 0:
blogs = []
else:
blogs = yield from Blog.findAll('hide=?', [False], orderBy='created_at desc')
for blog in blogs:
if ((blog.categorys_bit >> (int)(id)) & 1) == 1:
blog.categorys_tag = yield from categorys_bit2tag(blog.categorys_bit)
blogs_in_catgory.append(blog)
categorys = yield from Category.findAll(orderBy='weight desc')
for category in categorys:
category.relationNum = (yield from calcu_relation_num(category.id, hide_ignore = True))
return {
'__template__': 'blogs.html',
'page': page,
'blogs': blogs_in_catgory[page.offset : (page.offset + page.limit - 1)],
'categorys': categorys
}
示例2: categorys_bit2tag
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import findAll [as 别名]
def categorys_bit2tag(categorys_bit):
'''
Convert categorys from bit to tag, tag is a list of dict(category_id, category_name, category_checked).
'''
categorys_tag = []
categorys = yield from Category.findAll(orderBy='weight desc')
for category in categorys:
# category.id starts from 0
categorys_tag.append({
"category_id" : category.id,
"category_name" : category.name,
"category_checked" : True if ((categorys_bit >> int(category.id) & 1) == 1) else False
})
return categorys_tag
示例3: index
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import findAll [as 别名]
def index(*, page='1'):
page_index = get_page_index(page)
num = yield from Blog.findNumber('count(id)', 'hide=?', [False])
page = Page(num, page_index)
if num == 0:
blogs = []
else:
blogs = yield from Blog.findAll('hide=?', [False], orderBy='created_at desc', limit=(page.offset, page.limit))
for blog in blogs:
blog.categorys_tag = yield from categorys_bit2tag(blog.categorys_bit)
categorys = yield from Category.findAll(orderBy='weight desc')
for category in categorys:
category.relationNum = (yield from calcu_relation_num(category.id, hide_ignore = True))
return {
'__template__': 'blogs.html',
'page': page,
'blogs': blogs,
'categorys': categorys
}
示例4: api_get_categorys
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import findAll [as 别名]
def api_get_categorys(request):
check_admin(request)
categorys = yield from Category.findAll(orderBy='weight desc')
for category in categorys:
category.relationNum = (yield from calcu_relation_num(category.id))
return dict(categorys=categorys)