本文整理汇总了Python中pure_pagination.Paginator类的典型用法代码示例。如果您正苦于以下问题:Python Paginator类的具体用法?Python Paginator怎么用?Python Paginator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paginator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get
def get(self, request):
all_course = Course.objects.all().order_by('-add_time')
hot_course = all_course.order_by('-click_nums')[:3] # 热门课程
sort = request.GET.get('order', '')
if sort == 'hot':
all_course = all_course.order_by('-click_nums') # 按热门排序
elif sort == 'students':
all_course = all_course.order_by('-students') # 按人数排序
# 分页设置
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(all_course, 9, request=request)
courses = p.page(page)
return render(request, 'course-list.html', {
'all_course' : courses,
'MEDIA_URL' : MEDIA_URL,
'sort' : sort,
'hot_course' : hot_course,
})
开发者ID:ilib0x00000000,项目名称:NULL,代码行数:27,代码来源:views.py
示例2: get
def get(self, request, tag_name):
tag = get_object_or_404(Tag, name=tag_name)
tag_blogs = tag.blog_set.all()
# 博客、标签、分类数目统计
count_nums = Counts.objects.get(id=1)
blog_nums = count_nums.blog_nums
cate_nums = count_nums.category_nums
tag_nums = count_nums.tag_nums
# 分页
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(tag_blogs, 5, request=request)
tag_blogs = p.page(page)
return render(request, 'tag-detail.html', {
'tag_blogs': tag_blogs,
'tag_name': tag_name,
'blog_nums': blog_nums,
'cate_nums': cate_nums,
'tag_nums': tag_nums,
})
开发者ID:lufangfan,项目名称:django_blog,代码行数:25,代码来源:views.py
示例3: collection
def collection(request, collection_id):
collection = get_object_or_404(Collection, pk=collection_id)
if not can_view_collection(request.user, collection):
raise PermissionDenied
if request.GET.get('all', '') == 'on':
card_list = Card.objects.all()
else:
card_list = Card.objects.filter(editions__collection__id=collection_id)
card_list, ferrors = _filter_cards(request, card_list)
paginator = Paginator(card_list, 30, request=request)
page = request.GET.get('page', 1)
try:
entries = paginator.page(page)
except PageNotAnInteger:
entries = paginator.page(1)
except EmptyPage:
entries = paginator.page(paginator.num_pages)
entries.object_list = [(*card.get_count_in_collection(collection_id),
card) for card in entries.object_list]
layout = request.GET.get('layout', 'list')
if layout not in ['list', 'grid']:
layout = 'list'
return render(request, 'cardbox/collection.html', {
'collection': collection,
'entries': entries,
'get': request.GET,
'layout': layout,
'ferrors': ferrors,
})
开发者ID:bfrascher,项目名称:django-cardbox,代码行数:35,代码来源:views.py
示例4: get
def get(self, request):
all_teachers = Teacher.objects.all()
sorted_teacher = Teacher.objects.all().order_by('-click_nums')[:3]
search_keywords = request.GET.get('keywords', '')
if search_keywords:
all_teachers = all_teachers.filter(
Q(name__icontains=search_keywords) |
Q(work_company__icontains=search_keywords) |
Q(work_position__icontains=search_keywords)
)
sort = request.GET.get('sort', '')
if sort == 'hot':
all_teachers = all_teachers.order_by('-click_nums')
# 对讲师进行分页
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(all_teachers, 2, request=request)
teachers = p.page(page)
return render(request, 'teachers-list.html', {
'all_teachers': teachers,
'sorted_teacher': sorted_teacher,
'sort': sort,
})
开发者ID:116pythonZS,项目名称:imooc-django,代码行数:29,代码来源:views.py
示例5: get
def get(self, request, *args, **kwargs):
self.page = kwargs.get('page', 1)
self.current_tag = kwargs.get('tag', '')
if self.current_tag != '':
self.filter_tags.append(self.current_tag)
self.pictures = self.pictures.filter(
picture_tag__name=self.current_tag)
#set the tags
self.get_tags()
# set up paginator
paginator = Paginator(self.pictures, self.picture_per_page)
try:
self.pictures = paginator.page(self.page)
except PageNotAnInteger:
self.pictures = paginator.page(1)
except EmptyPage:
self.pictures = paginator.page(paginator.num_pages)
if request.is_ajax():
response = self.get_ajax()
else:
response = self.render_to_response({
'pictures': self.pictures,
'tags': self.tags,
'active_tag_count': self.active_tag_count,
'current_tag': self.current_tag,
})
return response
开发者ID:travishathaway,项目名称:thathweb,代码行数:32,代码来源:views.py
示例6: licitacoes_lista
def licitacoes_lista(request, modalidade=None, ano=None):
if modalidade:
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
try:
site = Site.objects.get(domain=request.get_host())
modalidade = modalidade
if not ano:
ano = str(timezone.now().year)
objects = Licitacao.publicados.filter(sites__id__exact=site.id, modalidade=modalidade,
data_publicacao__year=ano)
paginator = Paginator(objects, request=request, per_page=25)
licitacoes = paginator.page(page)
except Site.DoesNotExist, Licitacao.DoesNotExist:
raise Http404
anos = Licitacao.publicados.filter().datetimes('data_publicacao', 'year', order='DESC')
return render(request, 'conteudo/licitacoes_lista.html', {'licitacoes': licitacoes, 'anos': anos, 'ano': ano,
'modalidade': modalidade})
开发者ID:eldioschalm,项目名称:novo_portal,代码行数:27,代码来源:views.py
示例7: get
def get(self, request):
all_course = Course.objects.all()
# 热门课程推荐
hot_courses = Course.objects.all().order_by("-students")[:3]
# 搜索功能
search_keywords = request.GET.get('keywords', '')
if search_keywords:
# 在name字段进行操作,做like语句的操作。i代表不区分大小写
# or操作使用Q
all_course = all_course.filter(Q(name__icontains=search_keywords) | Q(desc__icontains=search_keywords) | Q(
detail__icontains=search_keywords))
# 对课程进行分页
# 尝试获取前台get请求传递过来的page参数
# 如果是不合法的配置参数默认返回第一页
# 进行排序
sort = request.GET.get('sort', "")
if sort:
if sort == "students":
all_course = all_course.order_by("-students")
elif sort == "hot":
all_course = all_course.order_by("-click_nums")
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
# 这里指从allorg中取五个出来,每页显示5个
p = Paginator(all_course, 6, request=request)
courses = p.page(page)
return render(request, "course-list.html", {
"all_course": courses,
"sort": sort,
"hot_courses": hot_courses,
"search_keywords": search_keywords
})
开发者ID:sloth-zpz,项目名称:Mxonline3,代码行数:34,代码来源:views.py
示例8: get_discussion
def get_discussion(request, discussion_id=None):
discussion = get_object_or_404(Discussion, id=discussion_id)
from itertools import chain
comments = list(chain([discussion], discussion.comments.all()))
try:
page = request.GET.get('side', 1)
except PageNotAnInteger:
page = 1
p = Paginator(comments, per_page=10, orphans=3, request=request)
try:
comments = p.page(page)
except EmptyPage:
comments = p.page(1)
variables = {
'pagetitle': discussion.title,
'discussion': get_object_or_404(Discussion, id=discussion_id),
'comments': comments,
'form': CommentForm(),
}
return render(request, 'discussion.html', variables)
开发者ID:tangram,项目名称:spilltelegrafen-django,代码行数:26,代码来源:views.py
示例9: index
def index(request):
#Uncomment the below block to use standard Django Pagination
# context=RequestContext(request)
# product_list=Product.objects.order_by('-time')
# paginator=Paginator(product_list,5)
# page=request.GET.get('page')
# try:
# products=paginator.page(page)
# except PageNotAnInteger:
# products=paginator.page(1)
# except EmptyPage:
# products=paginator.page(paginator.num_pages)
# context_dict={"products":products}
context=RequestContext(request)
product_list=Product.objects.order_by('-time')
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
# Provide Paginator with the request object for complete querystring generation
p = Paginator(product_list, 5,request=request)
products = p.page(page)
context_dict={"products":products}
return render_to_response('listing/index.html',context_dict,context)
开发者ID:rahulgupta92,项目名称:Push-Notifs,代码行数:33,代码来源:views.py
示例10: home
def home(request, template_name = 'main.html'):
res_post = False
try:
if len(request.session['posts']) > 0:
res_post = True
except:
res_post = False
try:
ind_list = Indicator.objects.order_by('Description')
except Indicator.DoesNotExist:
ind_list = True
if not ind_list == True:
paginator = Paginator(ind_list, 20)
page = request.POST.get('page',1)
try:
indicators = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
indicators = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
indicators = paginator.page(paginator.num_pages)
args = {}
args.update(csrf(request))
args['indicators'] = indicators
args['res_post'] = res_post
return render(request, template_name, args)
else:
posts = [{'page':'1'}]
args = {}
args.update(csrf(request))
args['all_posts'] = posts
args['res_post'] = res_post
return render(request, template_name, args)
开发者ID:ActonLeBrein,项目名称:World-Bank,代码行数:35,代码来源:views.py
示例11: get
def get(self, request):
all_teachers = Teacher.objects.all()
# 总共有多少老师使用count进行统计
teacher_nums = all_teachers.count()
# 搜索功能
search_keywords = request.GET.get('keywords', '')
if search_keywords:
# 在name字段进行操作,做like语句的操作。i代表不区分大小写
# or操作使用Q
all_teachers = all_teachers.filter(name__icontains=search_keywords)
# 人气排序
sort = request.GET.get("sort", "")
if sort == "hot":
all_teachers = all_teachers.order_by('-click_nums')
# 讲师排行榜
sorted_teacher = Teacher.objects.all().order_by("-click_nums")[:3]
# 进行分页
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(all_teachers, 5, request=request)
teachers = p.page(page)
return render(request, "teachers-list.html", {
"all_teachers": teachers,
"teacher_nums": teacher_nums,
'sorted_teacher': sorted_teacher,
'sort': sort,
})
开发者ID:Milleree,项目名称:DjangoEduSysDemo,代码行数:34,代码来源:views.py
示例12: get
def get(self, request):
all_courses = Course.objects.all().order_by("-add_time")
hot_courses = Course.objects.all().order_by("-click_nums")[:3]
# 课程排序
sort = request.GET.get('sort', "")
if sort:
if sort == "students":
all_courses = all_courses.order_by("-students")
elif sort == "hot":
all_courses = all_courses.order_by("-click_nums")
# 课程分页
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
# 设定每页显示3个
p = Paginator(all_courses, 3, request=request)
# 取到分页的课程并赋值给变量courses
courses = p.page(page)
return render(request, "course-list.html", {
"all_courses": courses,
"sort": sort,
"hot_courses": hot_courses,
})
开发者ID:jdk6979,项目名称:django,代码行数:27,代码来源:views.py
示例13: html_export
def html_export(request, username, id_string):
limit = request.REQUEST.get('limit', 100)
cursor = get_instances_for_user_and_form(username, id_string)
paginator = Paginator(cursor, limit, request=request)
try:
page = paginator.page(request.REQUEST.get('page', 1))
except (EmptyPage, PageNotAnInteger):
try:
page = paginator.page(1)
except (EmptyPage, PageNotAnInteger):
page = None
context = {
'page': page,
'table': []
}
if page:
data = [("v1", page.object_list)]
export = build_export(request, username, id_string)
context['table'] = mark_safe("\n".join(export.to_html(data)))
context['title'] = id_string
return render(request, 'export/export_html.html', context)
开发者ID:kimetrica,项目名称:kobocat,代码行数:27,代码来源:views.py
示例14: index
def index(request):
preferred_language = translation.get_language()
collator = Collator.createInstance(Locale(preferred_language))
if request.GET.get('aspect'):
aspect = request.GET['aspect']
else:
aspect = 'Collection'
try:
aspect_uri = ROUTABLES[aspect]
except KeyError:
aspect_uri = ROUTABLES['Collection']
this_results = []
for res in graph.subjects(RDF.type, aspect_uri):
r = Resource(graph,res)
if Resource(graph,UNBIST.PlaceName) in list(r[RDF.type]):
continue
res_label = get_preferred_label(res,preferred_language)
this_results.append({'uri': res, 'pref_label':res_label})
#sorted_results = sorted(this_results, key=lambda tup: tup['pref_label'], cmp=collator.compare)
sorted_results = sorted(this_results, key=lambda tup: tup['pref_label'])
try:
page = request.GET.get('page',1)
except PageNotAnInteger:
page = 1
p = Paginator(sorted_results, 20, request=request)
paginated_results = p.page(page)
return render(request, 'thesaurus/index.html', {'results': paginated_results, 'target': 'instances', 'aspect':aspect })
开发者ID:aaronhelton,项目名称:unlod,代码行数:33,代码来源:views.py
示例15: generic_list_view
def generic_list_view(request, blog_slug=None, category_slug=None):
feeds = Feed.objects.all()
feedextras = FeedExtra.objects.all()
if blog_slug:
this_feedextra = feedextras.filter(slug=blog_slug).first()
feed_pk = this_feedextra.feed.pk
print feed_pk
obj = Entry.objects.filter(feed=this_feedextra.feed).order_by('-date')
elif category_slug:
pass
else:
obj = Entry.objects.all().order_by('-date')
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
per_page = settings.PAGINATION_SETTINGS['ITEMS_PER_PAGE']
e = Paginator(obj, per_page, request=request)
entries = e.page(page)
context = {
'entries': entries,
'feeds': feeds,
'feedextras': feedextras,
}
return render(request, 'blog/pages/generic_list.html', context)
开发者ID:aejones89,项目名称:Data-science-blogs-3,代码行数:35,代码来源:views.py
示例16: character_journal
def character_journal(request):
character = get_object_or_404(CharacterApi, pk=request.session['charpk'])
if not character.api.access_to("WalletJournal"):
return HttpResponseRedirect(reverse("characters"))
all_transactions = character.wallet_journal()
filter_form = FilterJournalForm(
request.POST or None, characterapi=character
)
paginator = Paginator(
all_transactions,
50, request=request
)
page = request.GET.get('page', 1)
try:
transactions = paginator.page(page)
except PageNotAnInteger:
transactions = paginator.page(1)
except EmptyPage:
transactions = paginator.page(paginator.num_pages)
chart_list = CharacterJournal.monthly_balance(character)
return render(
request,
"characters/wallet_journal.html",
{
"character": character,
"transactions": transactions,
"chart_list": chart_list,
"filter_form": filter_form,
}
)
开发者ID:Sult,项目名称:evehub,代码行数:34,代码来源:views.py
示例17: get
def get(self, request):
all_courses = Course.objects.all().order_by("-add_time")
hot_courses = Course.objects.all().order_by("-click_nums")[:3]
# 课程搜索
search_keywords = request.GET.get("keywords", "")
if search_keywords:
all_courses = all_courses.filter(
Q(name__icontains=search_keywords) | Q(desc__icontains=search_keywords) | Q(
detail__icontains=search_keywords))
sort = request.GET.get("sort", "")
if sort:
if sort == "students":
all_courses = all_courses.order_by("-students")
elif sort == "hot":
all_courses = all_courses.order_by("-click_nums")
# 对课程进行分页
try:
page = request.GET.get("page", 1)
except PageNotAnInteger:
page = 1
p = Paginator(all_courses, 9, request=request)
courses = p.page(page)
return render(request, 'course-list.html', {
'all_courses': courses,
'sort': sort,
'hot_courses': hot_courses
})
开发者ID:xypisces,项目名称:python,代码行数:32,代码来源:views.py
示例18: build_page
def build_page(self):
"""
Paginates the results appropriately.
In case someone does not want to use Django's built-in pagination, it
should be a simple matter to override this method to do what they would
like.
"""
try:
page_no = int(self.request.GET.get('page', 1))
except (TypeError, ValueError):
raise Http404("Not a valid number for page.")
if page_no < 1:
raise Http404("Pages should be 1 or greater.")
start_offset = (page_no - 1) * self.results_per_page
self.results[start_offset:start_offset + self.results_per_page]
paginator = Paginator(self.results, self.results_per_page)
try:
page = paginator.page(page_no)
except InvalidPage:
raise Http404("No such page!")
return (paginator, page)
开发者ID:euanlau,项目名称:django-haystack,代码行数:27,代码来源:views.py
示例19: course_list
def course_list(request):
courses_list = Course.objects.all() # 展示全部数据
hot_courses = Course.objects.order_by('student_count')[0:2]
# 课程搜索
# search_keywords = request.GET.get('keywords','')
# if search_keywords:
# all_course = courses_list.filter(Q)
# 根据不同的标准,显示.sort是前端定义的,通过get可以获取不同的sort值,同搜索
sort = request.GET.get('sort','')
if sort:
if sort == 'students': # 根据学生量
courses_list = courses_list.order_by('-student_count')
elif sort == 'hot': # 根据点击量
courses_list = courses_list.order_by('-has_fav')
# 分页
try:
page = request.GET.get('page',1) # 获取页值,如果没有默认为1
except PageNotAnInteger :
page = 1
except EmptyPage:
page = 1
p = Paginator(courses_list,4,request=request) #这一步以及把course_list传入了p,分页器
courses = p.page(page) # 最终传入前端的是courses
return render(request,'course-list.html',locals())
开发者ID:leeway123,项目名称:mooc_project,代码行数:34,代码来源:views.py
示例20: adv_list
def adv_list(request):
try:
page = int(request.GET.get('page', 1))
except ValueError:
page = 1
ordering = {
'cu': 'city',
'cd': '-city',
'nu': 'title',
'nd': '-title',
'tu': 'add_time',
'td': '-add_time',
}
nu, cu, tu = 'nu', 'cu', 'tu'
what, where = '', ''
ord_get = request.GET.get('ord', 'td')
order = ordering.get(ord_get, '-add_time')
if ord_get == 'cu':
cu = 'cd'
elif ord_get == 'nu':
nu = 'nd'
elif ord_get == 'tu':
tu = 'td'
adv_list = Advert.objects.filter(enable=True)
form = SearchForm(request.GET)
if form.is_valid():
f = form.cleaned_data
what = f.get('what')
where = f.get('where')
if where == 'title':
adv_list = adv_list.filter(title__contains=what)
elif where == 'city':
adv_list = adv_list.filter(city__contains=what)
elif where == 'what':
adv_list = adv_list.filter(Q(what__contains=what) | \
Q(what_for__contains=what))
elif where == 'all':
adv_list = adv_list.filter(Q(what__contains=what) | \
Q(what_for__contains=what) | \
Q(city__contains=what) | \
Q(title__contains=what))
adv_list = adv_list.order_by(order)
p = Paginator(adv_list, 10, request=request)
adv_page = p.page(page)
adv_list = adv_page.object_list
return render(request, 'adv_list.html', locals())
开发者ID:ymre,项目名称:przygarnij,代码行数:56,代码来源:views.py
注:本文中的pure_pagination.Paginator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论