本文整理汇总了Python中django.core.paginator.Paginator方法的典型用法代码示例。如果您正苦于以下问题:Python paginator.Paginator方法的具体用法?Python paginator.Paginator怎么用?Python paginator.Paginator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.paginator
的用法示例。
在下文中一共展示了paginator.Paginator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: discussion_index
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [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: get
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [as 别名]
def get(self, request):
all_messages = UserMessage.objects.filter(user=request.user.id)
# 用户进入个人中心消息页面,清空未读消息记录
all_unread_messages = UserMessage.objects.filter(user=request.user.id, has_read=False)
for unread_message in all_unread_messages:
unread_message.has_read = True
unread_message.save()
# 对课程机构进行分页
# 尝试获取前台get请求传递过来的page参数
# 如果是不合法的配置参数默认返回第一页
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
# 这里指从allorg中取五个出来,每页显示5个
p = Paginator(all_messages, 4)
messages = p.page(page)
return render(request, "usercenter-message.html", {
"messages": messages
})
# 首页view
示例3: get_paginated_archive_issues
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [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 Paginator [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 Paginator [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: render
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [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 ''
示例7: search_category
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [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
}
)
示例8: search_tag
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [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
}
)
示例9: archives
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [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
}
)
示例10: dashboard
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [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 Paginator [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 Paginator [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 Paginator [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: search
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [as 别名]
def search(request):
q = request.GET.get('q', '')
if q != "":
petitions = Petition.objects.filter(Q(title__icontains=q) | Q(text__icontains=q)).filter(published=True)[:15]
orgs = Organization.objects.filter(name__icontains=q)
else:
petitions = Petition.objects.filter(published=True).order_by('-id')
paginator = Paginator(petitions, settings.PAGINATOR_COUNT)
page = request.GET.get('page')
petitions = paginator.get_page(page)
orgs = []
return render(
request, 'petition/search.html',
{
'petitions': petitions,
'orgs': orgs,
'q': q
}
)
示例15: user_profile
# 需要导入模块: from django.core import paginator [as 别名]
# 或者: from django.core.paginator import Paginator [as 别名]
def user_profile(request, user_name):
try:
user = PytitionUser.objects.get(user__username=user_name)
except PytitionUser.DoesNotExist:
raise Http404(_("not found"))
petitions = user.petition_set.filter(published=True).order_by('-id')
paginator = Paginator(petitions, settings.PAGINATOR_COUNT)
page = request.GET.get('page')
petitions = paginator.get_page(page)
return render(
request,
'petition/user_profile.html',
{'user': user, 'petitions': petitions}
)
# /org/<slug:orgslugname>/leave_org
# User is leaving the organisation