本文整理汇总了Python中django.core.paginator.InvalidPage方法的典型用法代码示例。如果您正苦于以下问题:Python paginator.InvalidPage方法的具体用法?Python paginator.InvalidPage怎么用?Python paginator.InvalidPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.paginator
的用法示例。
在下文中一共展示了paginator.InvalidPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: discussion_index
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def discussion_index(request, course_slug):
"""
Index page to view all discussion topics
"""
course, view = _get_course_and_view(request, course_slug)
if view is None:
# course is an HttpResponse in this case
return course
topics = DiscussionTopic.objects.filter(offering=course).order_by('-pinned', '-last_activity_at')
activity.update_last_viewed(_get_member(request.user.username, view, course_slug))
paginator = Paginator(topics, 10)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
topics = paginator.page(page)
except (EmptyPage, InvalidPage):
topics = paginator.page(paginator.num_pages)
context = {'course': course, 'topics': topics, 'view': view, 'paginator': paginator, 'page': page}
return render(request, 'discuss/index.html', context)
示例2: render
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def render(self, context):
key = self.queryset_var.var
value = self.queryset_var.resolve(context)
if isinstance(self.paginate_by, int):
paginate_by = self.paginate_by
else:
paginate_by = self.paginate_by.resolve(context)
paginator = Paginator(value, paginate_by, self.orphans)
try:
page_obj = paginator.page(context['request'].page)
except InvalidPage:
if INVALID_PAGE_RAISES_404:
raise Http404('Invalid page requested. If DEBUG were set to ' +
'False, an HTTP 404 page would have been shown instead.')
context[key] = []
context['invalid_page'] = True
return ''
if self.context_var is not None:
context[self.context_var] = page_obj.object_list
else:
context[key] = page_obj.object_list
context['paginator'] = paginator
context['page_obj'] = page_obj
return ''
示例3: paginate_queryset
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [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:
if page == 'last':
page_number = paginator.num_pages
else:
raise Http404(_("Page is not 'last', nor can it 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)
})
示例4: paginate_queryset
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [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:
if page == 'last':
page_number = paginator.num_pages
else:
raise Http404(_("Page is not 'last', nor can it 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)
})
示例5: page
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def page(self, number):
"""
Returns a Page object for the given 1-based page number.
Retrieves objects for the given page number plus 1 additional to check
if there are more objects after this page.
"""
number = self.validate_number(number)
offset = (number - 1) * self.per_page
limit = offset + self.per_page
object_list = list(self.object_list[offset:limit])
if not object_list and number != 1:
raise InvalidPage("That page contains no results")
return YTPage(object_list, number, self)
示例6: paginate_query_object
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [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)
示例7: record
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def record(request):
user = request.user.username
page_size = 10
all_record = OperateRecord.objects.order_by('-id')
paginator = Paginator(all_record, page_size)
try:
page = int(request.GET.get('page', 1))
except ValueError:
page = 1
# page_id = range(((page-1)*13+1),(page*13+1))
try:
posts = paginator.page(page)
except (EmptyPage, InvalidPage):
posts = paginator.page(paginator.num_pages)
return render(
request,
'record_list.html',
{'posts': posts,
# 'page_id': page_id,
}
)
示例8: paginate_queryset
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def paginate_queryset(self, queryset, page_size):
if not self.use_infinite_pagination:
return super().paginate_queryset(queryset, page_size)
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 cannot be converted to an int.')
try:
page = infinite_paginate(queryset, page_number, page_size, self.pad_pages)
return DummyPaginator(page_size), 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),
})
示例9: page
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def page(self, number):
"""
Returns a Page object for the given 1-based page number.
"""
number = self.validate_number(number)
offset = (number - 1) * self.per_page
limit = offset + self.per_page
object_list = self.object_list[offset:limit]
page = YTPage(object_list, number, self)
if not page.num_pages:
if number != 1 or not self.allow_empty_first_page:
raise InvalidPage("That page contains no results")
return page
示例10: paginate_queryset
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [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:
if page == 'last':
page_number = paginator.num_pages
else:
raise Http404(_("Page is not 'last', nor can it 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': force_text(e),
})
示例11: paginate_queryset
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def paginate_queryset(self, queryset, page_size):
"""
Paginate the queryset, if needed.
"""
paginator = self.get_paginator(queryset, page_size, 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:
if page == 'last':
page_number = paginator.num_pages
else:
raise Http404(_("Page is not 'last', nor can it 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)
})
示例12: render
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def render(self, context):
key = self.queryset_var.var
value = self.queryset_var.resolve(context)
if isinstance(self.paginate_by, int):
paginate_by = self.paginate_by
else:
paginate_by = self.paginate_by.resolve(context)
paginator = Paginator(value, paginate_by, self.orphans)
try:
page_obj = paginator.page(context['request'].page)
except InvalidPage:
if INVALID_PAGE_RAISES_404:
raise Http404('Invalid page requested. If DEBUG were set to ' +
'False, an HTTP 404 page would have been shown instead.')
context[key] = []
context['invalid_page'] = True
return u''
if self.context_var is not None:
context[self.context_var] = page_obj.object_list
else:
context[key] = page_obj.object_list
context['paginator'] = paginator
context['page_obj'] = page_obj
return u''
示例13: paginate_queryset
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [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)
})
示例14: make_result_list
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def make_result_list(self):
# Get search parameters from the query string.
self.base_queryset = self.queryset()
self.list_queryset = self.get_list_queryset()
self.ordering_field_columns = self.get_ordering_field_columns()
self.paginator = self.get_paginator()
# Get the number of objects, with admin filters applied.
self.result_count = self.paginator.count
self.can_show_all = self.result_count <= self.list_max_show_all
self.multi_page = self.result_count > self.list_per_page
# Get the list of objects to display on this page.
if (self.show_all and self.can_show_all) or not self.multi_page:
self.result_list = self.list_queryset._clone()
else:
try:
self.result_list = self.paginator.page(
self.page_num + 1).object_list
except InvalidPage:
if ERROR_FLAG in self.request.GET.keys():
return SimpleTemplateResponse('xadmin/views/invalid_setup.html', {
'title': _('Database error'),
})
return HttpResponseRedirect(self.request.path + '?' + ERROR_FLAG + '=1')
self.has_more = self.result_count > (
self.list_per_page * self.page_num + len(self.result_list))
示例15: get_results
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import InvalidPage [as 别名]
def get_results(self, request):
paginator = self.model_admin.get_paginator(request, self.queryset, self.list_per_page)
# Get the number of objects, with admin filters applied.
result_count = paginator.count
# Get the total number of objects, with no admin filters applied.
# Perform a slight optimization:
# full_result_count is equal to paginator.count if no filters
# were applied
if self.model_admin.show_full_result_count:
if self.get_filters_params() or self.params.get(SEARCH_VAR):
full_result_count = self.root_queryset.count()
else:
full_result_count = result_count
else:
full_result_count = None
can_show_all = result_count <= self.list_max_show_all
multi_page = result_count > self.list_per_page
# Get the list of objects to display on this page.
if (self.show_all and can_show_all) or not multi_page:
result_list = self.queryset._clone()
else:
try:
result_list = paginator.page(self.page_num + 1).object_list
except InvalidPage:
raise IncorrectLookupParameters
self.result_count = result_count
self.show_full_result_count = self.model_admin.show_full_result_count
# Admin actions are shown if there is at least one entry
# or if entries are not counted because show_full_result_count is disabled
self.show_admin_actions = not self.show_full_result_count or bool(full_result_count)
self.full_result_count = full_result_count
self.result_list = result_list
self.can_show_all = can_show_all
self.multi_page = multi_page
self.paginator = paginator