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


Python paginator.Page方法代碼示例

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


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

示例1: paginate_query_object

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def paginate_query_object(self, query_object, page_size):
        """Paginate the query object."""
        paginator = self.get_paginator(
            query_object, page_size,
            allow_empty_first_page=self.get_allow_empty())
        page = self.kwargs.get('page') or self.request.GET.get('page') or 1
        try:
            page_number = int(page)
        except ValueError:
            if page == 'last':
                page_number = paginator.num_pages
            else:
                raise InvalidPage("Page is not 'last', "
                                  "nor can it be converted to an int.")

        # DB2 fix for invalid 0 literal.
        # Generates FETCH 0 rows if not done this way
        if not paginator.count == 0:
            page = paginator.page(page_number)
            return (paginator, page, page.object_list, page.has_other_pages())
        else:
            return (paginator, Page([], 1, paginator), [], False) 
開發者ID:dealertrack,項目名稱:djangorest-alchemy,代碼行數:24,代碼來源:mixins.py

示例2: setUp

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def setUp(self):
        # Find root page
        self.root_page = Page.objects.get(id=1)

        # Find page with an associated site
        self.site_page = Page.objects.get(id=2)

        # Add another top-level page (which will have no corresponding site record)
        self.no_site_page = SimplePage(
            title="Hello world!",
            slug="hello-world",
            content="hello",
        )
        self.root_page.add_child(instance=self.no_site_page)

    # Tests for users that have both add-site permission, and explore permission at the given view;
    # warning messages should include advice re configuring sites 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:19,代碼來源:test_explorer_view.py

示例3: tests_paginate

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def tests_paginate(self):
        # first page
        items = list(range(0, 20))
        page = paginate(items, per_page=10)
        self.assertIsInstance(page, Page)
        self.assertEqual(list(page), items[:10])

        # second page
        page = paginate(items, per_page=10, page_number=2)
        self.assertEqual(list(page), items[10:20])

        # invalid page
        self.assertRaises(Http404, paginate,
                          items, per_page=10, page_number=99)

        # empty first page
        page = paginate([], per_page=10)
        self.assertListEqual(list(page), []) 
開發者ID:nitely,項目名稱:Spirit,代碼行數:20,代碼來源:tests_utils_paginator.py

示例4: data

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def data(self):
        """
        Returns the serialized data on the serializer.
        """
        if self._data is None:
            obj = self.object

            if self.many is not None:
                many = self.many
            else:
                many = hasattr(obj, '__iter__') and not isinstance(obj, (Page, dict))
                if many:
                    raise AssertionError('Implicit list/queryset serialization is deprecated. '
                                         'Use the `many=True` flag when instantiating the serializer.')

            if many:
                self._data = [self.to_native(item) for item in obj]
            else:
                self._data = self.to_native(obj)

        return self._data

    # noinspection PyMethodMayBeStatic 
開發者ID:erigones,項目名稱:esdc-ce,代碼行數:25,代碼來源:serializers.py

示例5: paginate_queryset

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def paginate_queryset(self, queryset, page_size):
    """
    Paginate the queryset, if needed.
    """
    paginator = self.get_paginator(
      queryset, page_size, orphans=self.get_paginate_orphans(),
      allow_empty_first_page=self.get_allow_empty())
    page_kwarg = self.page_kwarg
    page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1
    try:
      page_number = int(page)
    except ValueError:
      raise Http404(_("Page can not be converted to an int."))
    try:
      page = paginator.page(page_number)
      return (paginator, page, page.object_list, page.has_other_pages())
    except InvalidPage as e:
      raise Http404(_('Invalid page (%(page_number)s): %(message)s') % {
        'page_number': page_number,
        'message': str(e)
      }) 
開發者ID:F0RE1GNERS,項目名稱:eoj3,代碼行數:23,代碼來源:pagination.py

示例6: page

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def page(self, number):
        """
        Returns a Page object for the given 1-based page number.
        """
        number = self.validate_number(number)
        bottom = (number - 1) * self.per_page
        top = bottom + self.per_page
        page_items = self.object_list[bottom:top]
        # check moved from validate_number
        if not page_items:
            if number == 1 and self.allow_empty_first_page:
                pass
            else:
                raise EmptyPage('That page contains no results')
        return InfinitePage(page_items, number, self) 
開發者ID:raonyguimaraes,項目名稱:mendelmd,代碼行數:17,代碼來源:paginator.py

示例7: __repr__

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def __repr__(self):
        return '<Page %s>' % self.number 
開發者ID:raonyguimaraes,項目名稱:mendelmd,代碼行數:4,代碼來源:paginator.py

示例8: _data_convert

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def _data_convert(data, time_func, foreign, many, include_attr, exclude_attr):
    if isinstance(data, models.Model):
        attr_list = _get_attr(data, time_func, foreign, many)
        _include_check(include_attr, attr_list)
        _exclude_check(exclude_attr, attr_list)
        return attr_list
    elif isinstance(data, (QuerySet, Page)):
        result = []
        for itm in data:
            attr_list = _get_attr(itm, time_func, foreign, many)
            _include_check(include_attr, attr_list)
            _exclude_check(exclude_attr, attr_list)
            result.append(copy.copy(attr_list))
        return result
    elif isinstance(data, datetime.datetime):
        print '===='
        print data
        return time_func(data)
    elif isinstance(data, (unicode, str, bool, float)):
        return data
    elif isinstance(data, dict):
        for k, v in data.iteritems():
            data[k] = _data_convert(v, time_func, foreign, many, include_attr, exclude_attr)
        return data
    elif isinstance(data, list):
        for i, itm in enumerate(data):
            data[i] = _data_convert(itm, time_func, foreign, many, include_attr, exclude_attr)
        return data
    else:
        return None 
開發者ID:bluedazzle,項目名稱:django-angularjs-blog,代碼行數:32,代碼來源:Serializer.py

示例9: test_explore_root

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def test_explore_root(self):
        response = self.client.get(reverse('wagtailadmin_explore_root'))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailadmin/pages/index.html')
        self.assertEqual(Page.objects.get(id=1), response.context['parent_page'])
        self.assertTrue(response.context['pages'].paginator.object_list.filter(id=self.root_page.id).exists()) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:8,代碼來源:test_explorer_view.py

示例10: test_reordering

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def test_reordering(self):
        response = self.client.get(
            reverse('wagtailadmin_explore', args=(self.root_page.id, )),
            {'ordering': 'ord'}
        )
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailadmin/pages/index.html')
        self.assertEqual(response.context['ordering'], 'ord')

        # child pages should be ordered by native tree order (i.e. by creation time)
        page_ids = [page.id for page in response.context['pages']]
        self.assertEqual(page_ids, [self.child_page.id, self.old_page.id, self.new_page.id])

        # Pages must not be paginated
        self.assertNotIsInstance(response.context['pages'], paginator.Page) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:17,代碼來源:test_explorer_view.py

示例11: make_pages

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def make_pages(self):
        for i in range(150):
            self.root_page.add_child(instance=SimplePage(
                title="Page " + str(i),
                slug="page-" + str(i),
                content="hello",
            )) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:9,代碼來源:test_explorer_view.py

示例12: test_explore_with_missing_page_model

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def test_explore_with_missing_page_model(self):
        # Create a ContentType that doesn't correspond to a real model
        missing_page_content_type = ContentType.objects.create(app_label='tests', model='missingpage')
        # Turn /home/old-page/ into this content type
        Page.objects.filter(id=self.old_page.id).update(content_type=missing_page_content_type)

        # try to browse the the listing that contains the missing model
        response = self.client.get(reverse('wagtailadmin_explore', args=(self.root_page.id, )))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailadmin/pages/index.html')

        # try to browse into the page itself
        response = self.client.get(reverse('wagtailadmin_explore', args=(self.old_page.id, )))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailadmin/pages/index.html') 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:17,代碼來源:test_explorer_view.py

示例13: test_admin_can_explore_every_page

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def test_admin_can_explore_every_page(self):
        self.assertTrue(self.client.login(username='superman', password='password'))
        for page in Page.objects.all():
            response = self.client.get(reverse('wagtailadmin_explore', args=[page.pk]))
            self.assertEqual(response.status_code, 200) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:7,代碼來源:test_explorer_view.py

示例14: test_nonadmin_sees_breadcrumbs_up_to_cca

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def test_nonadmin_sees_breadcrumbs_up_to_cca(self):
        self.assertTrue(self.client.login(username='josh', password='password'))
        response = self.client.get(reverse('wagtailadmin_explore', args=[6]))
        self.assertEqual(response.status_code, 200)
        # While at "Page 1", Josh should see the breadcrumbs leading only as far back as the example.com homepage,
        # since it's his Closest Common Ancestor.
        self.assertInHTML(
            """<li class="home"><a href="/admin/pages/4/" class="icon icon-home text-replace">Home</a></li>""",
            str(response.content)
        )
        self.assertInHTML("""<li><a href="/admin/pages/5/">Content</a></li>""", str(response.content))
        # The page title shouldn't appear because it's the "home" breadcrumb.
        self.assertNotContains(response, "Welcome to example.com!") 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:15,代碼來源:test_explorer_view.py

示例15: render_paginator

# 需要導入模塊: from django.core import paginator [as 別名]
# 或者: from django.core.paginator import Page [as 別名]
def render_paginator(context, page, page_var='page', hashtag=''):
    query_dict = context["request"].GET.copy()

    try:
        del query_dict[page_var]
    except KeyError:
        pass

    extra_query = ""

    if query_dict:
        extra_query = "&%s" % query_dict.urlencode()

    if hashtag:
        hashtag = "#%s" % hashtag

    new_context = {
        "page": page,
        "page_var": page_var,
        "hashtag": hashtag,
        "extra_query": extra_query
    }

    if isinstance(page, Page):
        template = "spirit/utils/paginator/_paginator.html"
    else:
        template = "spirit/utils/paginator/_yt_paginator.html"

    return render_to_string(template, new_context) 
開發者ID:nitely,項目名稱:Spirit,代碼行數:31,代碼來源:paginator.py


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