當前位置: 首頁>>代碼示例>>Python>>正文


Python ArticleController.offset方法代碼示例

本文整理匯總了Python中web.controllers.ArticleController.offset方法的典型用法代碼示例。如果您正苦於以下問題:Python ArticleController.offset方法的具體用法?Python ArticleController.offset怎麽用?Python ArticleController.offset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在web.controllers.ArticleController的用法示例。


在下文中一共展示了ArticleController.offset方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: user_stream

# 需要導入模塊: from web.controllers import ArticleController [as 別名]
# 或者: from web.controllers.ArticleController import offset [as 別名]
def user_stream(per_page, nickname=None):
    """
    Display the stream of a user (list of articles of public feed).
    """
    user_contr = UserController()
    user = user_contr.get(nickname=nickname)
    if not user.is_public_profile:
        if current_user.is_authenticated and current_user.id == user.id:
            flash(gettext('You must set your profile to public.'), 'info')
        return redirect(url_for('user.profile'))

    category_id = int(request.args.get('category_id', 0))
    category = CategoryController().read(id=category_id).first()

    # Load the public feeds
    filters = {}
    filters['private'] = False
    if category_id:
        filters['category_id'] = category_id
    feeds = FeedController().read(**filters).all()

    # Re-initializes the filters to load the articles
    filters = {}
    filters['feed_id__in'] = [feed.id for feed in feeds]
    if category:
        filters['category_id'] = category_id
    articles = ArticleController(user.id).read_light(**filters)

    # Server-side pagination
    page, per_page, offset = get_page_args(per_page_parameter='per_page')
    pagination = Pagination(page=page, total=articles.count(),
                            css_framework='bootstrap3',
                            search=False, record_name='articles',
                            per_page=per_page)

    return render_template('user_stream.html', user=user,
                            articles=articles.offset(offset).limit(per_page),
                            category=category,
                            pagination=pagination)
開發者ID:JARR,項目名稱:JARR,代碼行數:41,代碼來源:user.py


注:本文中的web.controllers.ArticleController.offset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。