本文整理汇总了Python中django.core.paginator.EmptyPage方法的典型用法代码示例。如果您正苦于以下问题:Python paginator.EmptyPage方法的具体用法?Python paginator.EmptyPage怎么用?Python paginator.EmptyPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.paginator
的用法示例。
在下文中一共展示了paginator.EmptyPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_relations
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def get_relations(self):
paginator = self.get_paginator()
try:
page = paginator.page(int(self.request.GET.get('page', 1)))
except EmptyPage:
raise Http404()
objects = page.object_list
relations = {
self.relation: self.get_resources(page)
}
relations['first'] = self.__class__()
if page.has_next():
relations['next'] = self.__class__(page.next_page_number())
if page.has_previous():
relations['prev'] = self.__class__(page.previous_page_number())
if page.has_other_pages():
relations['last'] = self.__class__(paginator.num_pages)
return relations
示例2: discussion_index
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [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)
示例3: get_paginated_archive_issues
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def get_paginated_archive_issues(self, archive_issues, request):
items_per_page = 9
paginator = Paginator(archive_issues, items_per_page)
archive_issues_page = request.GET.get("page")
try:
paginated_archive_issues = paginator.page(archive_issues_page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
paginated_archive_issues = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
paginated_archive_issues = paginator.page(paginator.num_pages)
return paginated_archive_issues
示例4: get_paginated_memorials
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def get_paginated_memorials(self, filtered_memorials, request):
items_per_page = 10
paginator = Paginator(filtered_memorials, items_per_page)
memorials_page = request.GET.get("page")
try:
paginated_memorials = paginator.page(memorials_page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
paginated_memorials = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
paginated_memorials = paginator.page(paginator.num_pages)
return paginated_memorials
示例5: get_context
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def get_context(self, request, *args, **kwargs):
context = super().get_context(request)
upcoming_events = Event.objects.all().filter(
Q(date__gt=date.today())).order_by('date')
# Show three archive issues per page
paginator = Paginator(upcoming_events, 3)
upcoming_events_page = request.GET.get("page")
try:
paginated_events = paginator.page(upcoming_events_page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
paginated_events = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
paginated_events = paginator.page(paginator.num_pages)
context["events"] = paginated_events
return context
示例6: search_category
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def search_category(request, id):
posts = Article.objects.filter(category_id=str(id))
category = categories.get(id=str(id))
paginator = Paginator(posts, settings.PAGE_NUM) # 每页显示数量
try:
page = request.GET.get('page') # 获取URL中page参数的值
post_list = paginator.page(page)
except PageNotAnInteger:
post_list = paginator.page(1)
except EmptyPage:
post_list = paginator.page(paginator.num_pages)
return render(request, 'category.html',
{'post_list': post_list,
'category_list': categories,
'category': category,
'months': months
}
)
示例7: search_tag
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def search_tag(request, tag):
posts = Article.objects.filter(tags__name__contains=tag)
paginator = Paginator(posts, settings.PAGE_NUM) # 每页显示数量
try:
page = request.GET.get('page') # 获取URL中page参数的值
post_list = paginator.page(page)
except PageNotAnInteger:
post_list = paginator.page(1)
except EmptyPage:
post_list = paginator.page(paginator.num_pages)
return render(request, 'tag.html', {
'post_list': post_list,
'category_list': categories,
'tag': tag,
'months': months
}
)
示例8: archives
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def archives(request, year, month):
posts = Article.objects.filter(pub_time__year=year, pub_time__month=month).order_by('-pub_time')
paginator = Paginator(posts, settings.PAGE_NUM) # 每页显示数量
try:
page = request.GET.get('page') # 获取URL中page参数的值
post_list = paginator.page(page)
except PageNotAnInteger:
post_list = paginator.page(1)
except EmptyPage:
post_list = paginator.page(paginator.num_pages)
return render(request, 'archive.html', {
'post_list': post_list,
'category_list': categories,
'months': months,
'year_month': year+'.'+month
}
)
示例9: validate_number
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def validate_number(self, number):
"""
Validates the given 1-based page number.
"""
try:
number = int(number)
except (TypeError, ValueError):
raise PageNotAnInteger('That page number is not an integer')
if number < 1:
raise EmptyPage('That page number is less than 1')
if number > self.num_pages:
if number == 1 and self.allow_empty_first_page:
pass
else:
number = self.num_pages
return number
示例10: dashboard
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def dashboard(request):
bls = BusinessLine.authorization.for_user(request.user, 'incidents.view_incidents')
bl_filter = Q(business_line__in=bls) | Q(business_line__isnull=True)
todos = TodoItem.objects.filter(incident__isnull=False, done=False).filter(bl_filter)
todos = todos.select_related('incident', 'category')
todos = todos.order_by('-incident__date')
page = request.GET.get('page', 1)
todos_per_page = request.user.profile.incident_number
p = Paginator(todos, todos_per_page)
try:
todos = p.page(page)
except (PageNotAnInteger, EmptyPage):
todos = p.page(1)
return render(request, 'fir_todos/dashboard.html', {'todos': todos})
示例11: page_it
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def page_it(data, record_per_page, page=''):
"""
return the data of the current page
"""
paginator = Paginator(data, record_per_page)
try:
data = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
data = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999),
# deliver last page of results.
data = paginator.page(paginator.num_pages)
return data
示例12: get_context_data
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def get_context_data(self, **kwargs):
logger.debug('GET: ListMissionView')
context = super(ListMissionView, self).get_context_data(**kwargs)
missions = Mission.objects.all()
paginator = Paginator(missions, 10)
page = self.request.GET.get('page')
try:
show_missions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
show_missions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
show_missions = paginator.page(paginator.num_pages)
context['missions'] = show_missions
return context
示例13: get_data
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def get_data(self):
page_offset = self.request.GET.get('page_offset')
results = []
if page_offset is None:
page_offset = 0
limit = utils.get_page_size(self.request)
try:
results = api.monitor.alarmdef_list(self.request, page_offset, limit)
paginator = Paginator(results, limit)
results = paginator.page(1)
except EmptyPage:
results = paginator.page(paginator.num_pages)
except Exception as ex:
LOG.exception(str(ex))
messages.error(self.request, _("Could not retrieve alarm definitions"))
return results
示例14: comment_list
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def comment_list(request, post_id):
post = Post.objects.get(id=post_id)
comments_all_list = Comment.objects.filter(post=post, is_deleted=False).order_by('-id')
paginator = Paginator(comments_all_list, post.board.comments_chunk_size)
page = request.GET.get('page')
try:
comments = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
comments = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
comments = paginator.page(paginator.num_pages)
pages_nav_info = get_pages_nav_info(comments, nav_chunk_size=post.board.comment_pages_nav_chunk_size)
return render(request, 'comment_list.html', {
'post': post,
'comments': comments,
'pages_nav_info': pages_nav_info
})
示例15: index
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import EmptyPage [as 别名]
def index(request):
POSTS_PER_PAGE = 5
if request.user.is_superuser:
post_list = Post.objects.all().order_by('-post_date')
else:
#post_list = Post.objects.filter(published=True).order_by('-post_date')
post_list = get_Posts_By_Language_Code(request.LANGUAGE_CODE)
paginator = Paginator(post_list, POSTS_PER_PAGE)
page = request.GET.get('page')
try:
posts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
posts = paginator.page(1)
except EmptyPage:
# If page is out of range, deliver last page of results.
posts = paginator.page(paginator.num_pages)
return render(request, 'blogApp/index.html', {'posts': posts})