当前位置: 首页>>代码示例>>Python>>正文


Python Category.findAll方法代码示例

本文整理汇总了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
    }
开发者ID:dramenk,项目名称:awesome,代码行数:30,代码来源:handlers.py

示例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
开发者ID:dramenk,项目名称:awesome,代码行数:16,代码来源:handlers.py

示例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
    }
开发者ID:dramenk,项目名称:awesome,代码行数:21,代码来源:handlers.py

示例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)
开发者ID:dramenk,项目名称:awesome,代码行数:8,代码来源:handlers.py


注:本文中的models.Category.findAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。