• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python shortcuts.paginate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中misago.core.shortcuts.paginate函数的典型用法代码示例。如果您正苦于以下问题:Python paginate函数的具体用法?Python paginate怎么用?Python paginate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了paginate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, request, thread, page):
        try:
            thread_model = thread.unwrap()
        except AttributeError:
            thread_model = thread

        posts_queryset = self.get_queryset(request, thread_model)

        list_page = paginate(
            posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL)
        paginator = pagination_dict(list_page, include_page_range=False)

        posts = list(list_page.object_list)
        posters = []

        for post in posts:
            post.category = thread.category
            post.thread = thread_model

            if post.poster:
                posters.append(post.poster)

        add_acl(request.user, posts)

        make_posts_read_aware(request.user, thread_model, posts)
        make_users_status_aware(request.user, posters)

        if thread.category.acl['can_see_posts_likes']:
            add_likes_to_posts(request.user, posts)

        self._user = request.user

        self.posts = posts
        self.paginator = paginator
开发者ID:1905410,项目名称:Misago,代码行数:34,代码来源:posts.py


示例2: list

    def list(self, page=0):
        queryset = exclude_invisible_threads(
            self.user, self.forum, self.forum.thread_set)
        queryset = self.filter_threads(queryset)
        queryset = queryset.order_by(*self.sort_by)

        announcements_qs = queryset.filter(weight=ANNOUNCEMENT)
        threads_qs = queryset.filter(weight__lt=ANNOUNCEMENT)

        self._page = paginate(threads_qs, page, 20, 10)
        self._paginator = self._page.paginator

        threads = []
        for announcement in announcements_qs:
            threads.append(announcement)
        for thread in self._page.object_list:
            threads.append(thread)

        for thread in threads:
            thread.forum = self.forum

        self.label_threads(threads, self.forum.labels)
        self.make_threads_read_aware(threads)

        return threads
开发者ID:dahito,项目名称:Misago,代码行数:25,代码来源:forum.py


示例3: list

    def list(self, page=0):
        queryset = self.get_queryset()
        queryset = queryset.order_by(self.sort_by)

        pinned_qs = queryset.filter(is_pinned=True)
        threads_qs = queryset.filter(is_pinned=False)

        self._page = paginate(threads_qs, page, 20, 10)
        self._paginator = self._page.paginator

        threads = []
        if self.fetch_pinned_threads:
            for thread in pinned_qs:
                threads.append(thread)
            self.pinned_count += 1
        for thread in self._page.object_list:
            threads.append(thread)

        for thread in threads:
            thread.forum = self.forum

        self.label_threads(threads, self.forum.labels)
        self.make_threads_read_aware(threads)

        return threads
开发者ID:Backenkoehler,项目名称:Misago,代码行数:25,代码来源:threads.py


示例4: __init__

    def __init__(self, request, category, list_type, page):
        self.allow_see_list(request, category, list_type)

        base_queryset = self.get_base_queryset(request, category.categories, list_type)
        threads_categories = [category.category] + category.subcategories

        threads_queryset = self.get_remaining_threads_queryset(base_queryset, category.category, threads_categories)

        list_page = paginate(threads_queryset, page, settings.MISAGO_THREADS_PER_PAGE, settings.MISAGO_THREADS_TAIL)
        paginator = pagination_dict(list_page, include_page_range=False)

        if list_page.number > 1:
            threads = list(list_page.object_list)
        else:
            pinned_threads = list(self.get_pinned_threads(base_queryset, category.category, threads_categories))
            threads = list(pinned_threads) + list(list_page.object_list)

        if list_type in ('new', 'unread'):
            # we already know all threads on list are unread
            threadstracker.make_unread(threads)
        else:
            threadstracker.make_threads_read_aware(request.user, threads)

        add_categories_to_threads(category.category, category.categories, threads)
        add_acl(request.user, threads)
        make_subscription_aware(request.user, threads)

        # set state on object for easy access from hooks
        self.category = category
        self.threads = threads
        self.list_type = list_type
        self.paginator = paginator
开发者ID:h094071,项目名称:Misago,代码行数:32,代码来源:threads.py


示例5: warnings

def warnings(request, profile, page=0):
    warnings_qs = profile.warnings.order_by('-id')
    warnings = paginate(warnings_qs, page, 5, 2)
    items_left = warnings.paginator.count - warnings.end_index()

    add_acl(request.user, warnings.object_list)

    warning_level = get_user_warning_level(profile)
    warning_level_obj = get_user_warning_obj(profile)

    active_warnings = warning_level - warnings.start_index() + 1
    for warning in warnings.object_list:
        if warning.is_canceled:
            warning.is_active = False
        else:
            warning.is_active = active_warnings > 0
            active_warnings -= 1

    levels_total = len(get_warning_levels()) - 1
    if levels_total and warning_level:
        warning_progress = 100 - warning_level * 100 / levels_total
    else:
        warning_progress = 100

    if warning_level:
        warning_level_obj.level = warning_level

    return render(request, 'misago/profile/warnings.html', {
        'profile': profile,
        'warnings': warnings,
        'warning_level': warning_level_obj,
        'warning_progress': warning_progress,
        'page_number': warnings.number,
        'items_left': items_left
    })
开发者ID:David1119,项目名称:Misago,代码行数:35,代码来源:profile.py


示例6: __init__

    def __init__(self, request, thread, page):
        posts_queryset = self.get_queryset(request, thread.model)

        list_page = paginate(posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL)
        paginator = pagination_dict(list_page, include_page_range=False)

        posts = list(list_page.object_list)
        posters = []

        for post in posts:
            post.category = thread.category
            post.thread = thread.model

            if post.poster:
                posters.append(post.poster)

        add_acl(request.user, posts)

        make_posts_read_aware(request.user, thread.model, posts)
        make_users_status_aware(request.user, posters)

        self._user = request.user

        self.posts = posts
        self.paginator = paginator
开发者ID:l0ud,项目名称:Misago,代码行数:25,代码来源:posts.py


示例7: rank

def rank(request, rank_slug, page=0):
    rank = get_object_or_404(Rank.objects.filter(is_tab=True), slug=rank_slug)
    queryset = rank.user_set.select_related('rank').order_by('slug')

    page = paginate(queryset, page, settings.MISAGO_USERS_PER_PAGE, 4)
    paginator = pagination_dict(page)

    request.frontend_context['USERS'] = dict(
        results=UserSerializer(page.object_list, many=True).data,
        **paginator
    )

    if rank.description:
        description = {
            'plain': rank.description,
            'html': format_plaintext_for_html(rank.description)
        }
    else:
        description = None

    template = "misago/userslists/rank.html"
    return render(request, template, {
        'rank': rank,
        'users': page.object_list,

        'paginator': paginator
    })
开发者ID:fengrussell,项目名称:Misago,代码行数:27,代码来源:lists.py


示例8: get_threads

    def get_threads(self, request, kwargs):
        queryset = self.get_threads_queryset(request, forum)
        queryset = threads_qs.order_by('-last_post_id')

        page = paginate(threads_qs, kwargs.get('page', 0), 30, 10)
        threads = [thread for thread in page.object_list]

        return page, threads
开发者ID:dahito,项目名称:Misago,代码行数:8,代码来源:threads.py


示例9: test_paginated_response_data_serializer

def test_paginated_response_data_serializer(request):
    data = [0, 1, 2, 3]
    page = paginate(data, 0, 10)

    return paginated_response(
        page,
        data=['a', 'b', 'c', 'd'],
        serializer=MockSerializer,
    )
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:9,代码来源:views.py


示例10: __init__

    def __init__(self, request, thread, page):
        try:
            thread_model = thread.unwrap()
        except AttributeError:
            thread_model = thread

        posts_queryset = self.get_posts_queryset(request, thread_model)

        posts_limit = settings.MISAGO_POSTS_PER_PAGE
        posts_orphans = settings.MISAGO_POSTS_TAIL
        list_page = paginate(
            posts_queryset, page, posts_limit, posts_orphans, paginator=PostsPaginator
        )
        paginator = pagination_dict(list_page)

        posts = list(list_page.object_list)
        posters = []

        for post in posts:
            post.category = thread.category
            post.thread = thread_model

            if post.poster:
                posters.append(post.poster)

        make_users_status_aware(request.user, posters)

        if thread.category.acl['can_see_posts_likes']:
            add_likes_to_posts(request.user, posts)

        # add events to posts
        if thread_model.has_events:
            first_post = None
            if list_page.has_previous():
                first_post = posts[0]
            last_post = None
            if list_page.has_next():
                last_post = posts[-1]

            events_limit = settings.MISAGO_EVENTS_PER_PAGE
            posts += self.get_events_queryset(
                request, thread_model, events_limit, first_post, last_post
            )

            # sort both by pk
            posts.sort(key=lambda p: p.pk)

        # make posts and events ACL and reads aware
        add_acl(request.user, posts)
        make_posts_read_aware(request.user, thread_model, posts)

        self._user = request.user

        self.posts = posts
        self.paginator = paginator
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:55,代码来源:posts.py


示例11: name_history

def name_history(request, profile, page=0):
    name_changes_qs = profile.namechanges.all().order_by('-id')
    name_changes = paginate(name_changes_qs, page, 12, 4)
    items_left = name_changes.paginator.count - name_changes.end_index()

    return render(request, 'misago/profile/name_history.html', {
        'profile': profile,
        'name_changes': name_changes,
        'page_number': name_changes.number,
        'items_left': items_left
    })
开发者ID:David1119,项目名称:Misago,代码行数:11,代码来源:profile.py


示例12: test_paginated_response_data_extra

def test_paginated_response_data_extra(request):
    data = [0, 1, 2, 3]
    page = paginate(data, 0, 10)

    return paginated_response(
        page,
        data=['a', 'b', 'c', 'd'],
        extra={
            'next': 'EXTRA',
            'lorem': 'ipsum',
        },
    )
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:12,代码来源:views.py


示例13: get_posts

    def get_posts(self, user, forum, thread, kwargs):
        queryset = self.get_posts_queryset(user, forum, thread)
        page = paginate(queryset, kwargs.get('page', 0), 10, 5)

        posts = []
        for post in page.object_list:
            add_acl(user, post)
            if post.poster:
                poster_state = get_user_state(post.poster, user.acl)
                post.poster.online_state = poster_state
            posts.append(post)

        return page, posts
开发者ID:dahito,项目名称:Misago,代码行数:13,代码来源:thread.py


示例14: follows

def follows(request, profile, page=0):
    followers_qs = profile.follows.order_by('slug')
    followers = paginate(followers_qs, page, 6 * 4, 6)
    items_left = followers.paginator.count - followers.end_index()

    if followers.paginator.count != profile.following:
        profile.following = followers.paginator.count
        profile.save(update_fields=['following'])

    return render(request, 'misago/profile/follows.html', {
        'profile': profile,
        'followers': followers,
        'items_left': items_left,
    })
开发者ID:David1119,项目名称:Misago,代码行数:14,代码来源:profile.py


示例15: follows

def follows(request, profile):
    queryset = profile.follows.select_related('rank').order_by('slug')

    page = paginate(queryset, None, settings.MISAGO_USERS_PER_PAGE, 4)
    paginator = pagination_dict(page)

    request.frontend_context['PROFILE_FOLLOWS'] = dict(
        results=UserSerializer(page.object_list, many=True).data,
        **paginator
    )

    return render(request, 'misago/profile/follows.html', {
        'profile': profile,
        'follows': page.object_list,
    })
开发者ID:nescode,项目名称:Misago,代码行数:15,代码来源:profile.py


示例16: get_context_data

    def get_context_data(self, request, profile):
        queryset = profile.namechanges.select_related('user', 'changed_by')
        queryset = queryset.order_by('-id')

        page = paginate(queryset, None, 14, 4)

        data = pagination_dict(page)
        data.update({'results': UsernameChangeSerializer(page.object_list, many=True).data})

        request.frontend_context['PROFILE_NAME_HISTORY'] = data

        return {
            'history': page.object_list,
            'count': data['count'],
        }
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:15,代码来源:profile.py


示例17: list

    def list(self, request):
        page = get_int_or_404(request.query_params.get('page', 0))
        if page == 1:
            page = 0  # api allows explicit first page

        queryset = self.get_queryset()

        list_page = paginate(queryset, page, 12, 4)

        data = pagination_dict(list_page)
        data.update({
            'results': UsernameChangeSerializer(list_page.object_list, many=True).data,
        })

        return Response(data)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:15,代码来源:usernamechanges.py


示例18: __call__

    def __call__(self, request):
        try:
            page = int(request.query_params.get('page', 0))
        except ValueError:
            raise Http404()

        list_type = request.query_params.get('list') or 'all'
        if list_type not in LIST_TYPES:
            raise Http404()

        category = self.get_category(request)

        self.allow_see_list(request, category, list_type)

        subcategories = self.get_subcategories(request, category)
        categories = [category] + subcategories

        queryset = self.get_queryset(
            request, categories, list_type).order_by('-last_post_on')

        page = paginate(queryset, page, 24, 6, allow_explicit_first_page=True)
        response_dict = pagination_dict(page, include_page_range=False)

        if list_type in ('new', 'unread'):
            """we already know all threads on list are unread"""
            threadstracker.make_unread(page.object_list)
        else:
            threadstracker.make_threads_read_aware(
                request.user, page.object_list)
        add_categories_to_threads(categories, page.object_list)

        visible_subcategories = []
        for thread in page.object_list:
            if (thread.top_category and
                    thread.top_category not in visible_subcategories):
                visible_subcategories.append(thread.top_category.pk)

        if self.serialize_subcategories:
            response_dict['subcategories'] = []
            for subcategory in subcategories:
                if subcategory.pk in visible_subcategories:
                    response_dict['subcategories'].append(subcategory.pk)

        add_acl(request.user, page.object_list)

        return Response(dict(
            results=ThreadListSerializer(page.object_list, many=True).data,
            **response_dict))
开发者ID:fengrussell,项目名称:Misago,代码行数:48,代码来源:list.py


示例19: name_history

def name_history(request, profile):
    queryset = profile.namechanges.select_related('user', 'changed_by')
    queryset = queryset.order_by('-id')

    page = paginate(queryset, None, settings.MISAGO_USERS_PER_PAGE, 4)
    paginator = pagination_dict(page)

    request.frontend_context['PROFILE_NAME_HISTORY'] = dict(
        results=UsernameChangeSerializer(page.object_list, many=True).data,
        **paginator
    )

    return render(request, 'misago/profile/name_history.html', {
        'profile': profile,
        'history': page.object_list,
    })
开发者ID:nescode,项目名称:Misago,代码行数:16,代码来源:profile.py


示例20: __init__

    def __init__(self, request, profile, page=0):
        root_category = ThreadsRootCategory(request)
        threads_categories = [root_category.unwrap()] + root_category.subcategories

        threads_queryset = self.get_threads_queryset(
            request, threads_categories, profile)
        posts_queryset = self.get_posts_queryset(
            request.user, profile, threads_queryset
            ).filter(
                is_event=False,
                is_hidden=False,
                is_unapproved=False
            ).order_by('-pk')

        list_page = paginate(
            posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL)
        paginator = pagination_dict(list_page, include_page_range=False)

        posts = list(list_page.object_list)

        posters = []
        threads = []

        for post in posts:
            threads.append(post.thread)

            if post.poster:
                posters.append(post.poster)

        add_categories_to_items(
            root_category.unwrap(), threads_categories, posts + threads)

        add_acl(request.user, threads)
        add_acl(request.user, posts)

        threadstracker.make_threads_read_aware(request.user, threads)
        for post in posts:
            threadstracker.make_posts_read_aware(request.user, post.thread, [post])

        add_likes_to_posts(request.user, posts)

        make_users_status_aware(request.user, posters)

        self._user = request.user

        self.posts = posts
        self.paginator = paginator
开发者ID:NotKit,项目名称:Misago,代码行数:47,代码来源:threads.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.slugify函数代码示例发布时间:2022-05-27
下一篇:
Python shortcuts.get_object_or_404函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap