本文整理匯總了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)