本文整理汇总了Python中mezzanine.utils.views.paginate函数的典型用法代码示例。如果您正苦于以下问题:Python paginate函数的具体用法?Python paginate怎么用?Python paginate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了paginate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: page_lists
def page_lists(request, page):
page_posts = RichTextPage.objects.published(for_user=request.user).filter(parent=page).order_by("-publish_date")
paginate(page_posts, request.GET.get("page", 1),
settings.BLOG_POST_PER_PAGE,
settings.MAX_PAGING_LINKS)
return {'page_posts': page_posts}
开发者ID:jimmykuu,项目名称:mezzanine_category,代码行数:7,代码来源:page_processors.py
示例2: blog_post_list
def blog_post_list(request, tag=None, year=None, month=None, username=None,
category=None, template="blog/blog_post_list.html"):
"""
Display a list of blog posts that are filtered by tag, year, month,
author or category. Custom templates are checked for using the name
``blog/blog_post_list_XXX.html`` where ``XXX`` is either the
category slug or author's username if given.
"""
settings.use_editable()
templates = []
blog_posts = BlogPost.objects.published(for_user=request.user)
if tag is not None:
tag = get_object_or_404(Keyword, slug=tag)
blog_posts = blog_posts.filter(keywords__in=tag.assignments.all())
if year is not None:
blog_posts = blog_posts.filter(publish_date__year=year)
if month is not None:
blog_posts = blog_posts.filter(publish_date__month=month)
month = month_name[int(month)]
if category is not None:
category = get_object_or_404(BlogCategory, slug=category)
blog_posts = blog_posts.filter(categories=category)
templates.append(u"blog/blog_post_list_%s.html" %
unicode(category.slug))
author = None
if username is not None:
author = get_object_or_404(User, username=username)
blog_posts = blog_posts.filter(user=author)
templates.append(u"blog/blog_post_list_%s.html" % username)
# Create dicts mapping blog post IDs to lists of categories and
# keywords, and assign these to each blog post, to avoid querying
# the database inside the template loop for posts.
blog_posts = list(blog_posts.select_related("user"))
categories = defaultdict(list)
if blog_posts:
ids = ",".join([str(p.id) for p in blog_posts])
for cat in BlogCategory.objects.raw(
"SELECT * FROM blog_blogcategory "
"JOIN blog_blogpost_categories "
"ON blog_blogcategory.id = blogcategory_id "
"WHERE blogpost_id IN (%s)" % ids):
categories[cat.blogpost_id].append(cat)
keywords = defaultdict(list)
blogpost_type = ContentType.objects.get(app_label="blog", model="blogpost")
assigned = AssignedKeyword.objects.filter(blogpost__in=blog_posts,
content_type=blogpost_type).select_related("keyword")
for a in assigned:
keywords[a.object_pk].append(a.keyword)
for i, post in enumerate(blog_posts):
setattr(blog_posts[i], "category_list", categories[post.id])
setattr(blog_posts[i], "keyword_list", keywords[post.id])
blog_posts = paginate(blog_posts,
request.GET.get("page", 1),
settings.BLOG_POST_PER_PAGE,
settings.MAX_PAGING_LINKS)
context = {"blog_page": blog_page(), "blog_posts": blog_posts,
"year": year, "month": month, "tag": tag,
"category": category, "author": author}
templates.append(template)
return render(request, templates, context)
开发者ID:n1k0,项目名称:mezzanine,代码行数:60,代码来源:views.py
示例3: article_list
def article_list(request, tag=None, category=None, template="article/article_list.html"):
"""
Display a list of blog posts that are filtered by tag, year, month,
author or category. Custom templates are checked for using the name
``blog/blog_post_list_XXX.html`` where ``XXX`` is either the
category slug or author's username if given.
"""
settings.use_editable()
templates = []
articles = Article.objects.published(for_user=request.user)
if tag is not None:
tag = get_object_or_404(Keyword, slug=tag)
articles = articles.filter(keywords__in=tag.assignments.all())
if category is not None:
category = get_object_or_404(BlogCategory, slug=category)
articles = articles.filter(categories=category)
# templates.append(u"article/blog_post_list_%s.html" %
# str(category.slug))
author = None
prefetch = ("categories", "keywords__keyword")
articles = articles.select_related("user").prefetch_related(*prefetch)
articles = paginate(articles, request.GET.get("page", 1),
settings.BLOG_POST_PER_PAGE,
settings.MAX_PAGING_LINKS)
context = {"articles": articles,
"tag": tag, "category": category, "author": author}
templates.append(template)
return render(request, templates, context)
开发者ID:mihirk,项目名称:vikalp,代码行数:28,代码来源:views.py
示例4: search
def search(request, template="search_results.html"):
"""
Display search results. Takes an optional "contenttype" GET parameter
in the form "app-name.ModelName" to limit search results to a single model.
"""
settings.use_editable()
query = request.GET.get("q", "")
page = request.GET.get("page", 1)
per_page = settings.SEARCH_PER_PAGE
max_paging_links = settings.MAX_PAGING_LINKS
try:
search_model = get_model(*request.GET.get("type", "").split(".", 1))
if not issubclass(search_model, Displayable):
raise TypeError
except TypeError:
search_model = Displayable
search_type = _("Everything")
else:
search_type = search_model._meta.verbose_name_plural.capitalize()
results = search_model.objects.search(query, for_user=request.user)
if 'location' and 'age' in request.session:
if 'cart loaded' in request.session:
stores = request.session['stores']
else:
avail_store_ids = request.session['store ids']
if avail_store_ids:
stores = Store.objects.filter(id__in=avail_store_ids)
else:
return HttpResponseRedirect('/shop/no-stores-yet')
avail_prod_ids = []
for p in stores:
for k in results:
if p == k.store:
avail_prod_ids.append(k.id)
results = Product.objects.filter(id__in=avail_prod_ids)
sort_options = [(slugify(option[0]), option[1])
for option in settings.SHOP_PRODUCT_SORT_OPTIONS]
sort_by = request.GET.get("sort", sort_options[0][1])
results = paginate(results.order_by(sort_by),
request.GET.get("page", 1),
settings.SHOP_PER_PAGE_CATEGORY,
settings.MAX_PAGING_LINKS)
results.sort_by = sort_by
else:
# return render(request, template, {"have_loc": False})
info(request, _("Enter your location to use the search"))
return HttpResponseRedirect('/')
# paginated = paginate(results, page, per_page, max_paging_links)
paginated = results
context = {"query": query, "results": paginated,
"search_type": search_type, "have_loc": True}
return render(request, template, context)
开发者ID:obsjames,项目名称:md-production-public,代码行数:60,代码来源:views.py
示例5: show_forum
def show_forum(request, forum_id, full=True):
forum = get_object_or_404(Forum, pk=forum_id)
if not forum.category.has_access(request.user):
raise PermissionDenied
topics = forum.topics.order_by('-sticky', '-updated').select_related()
topics = paginate(topics, request.GET.get("page", 1),
forum_settings.FORUM_PAGE_SIZE, 20)
moderator = request.user.is_superuser or\
request.user in forum.moderators.all()
categories = []
for category in Category.objects.all():
if category.has_access(request.user):
categories.append(category)
to_return = {'categories': categories,
'forum': forum,
'posts': forum.post_count,
'topics': topics,
'moderator': moderator,
}
if full:
return render(request, 'djangobb_forum/forum.html', to_return)
else:
return render(request, 'djangobb_forum/lofi/forum.html', to_return)
开发者ID:agepoly,项目名称:DjangoBB,代码行数:25,代码来源:views.py
示例6: have_location_get_categories_products
def have_location_get_categories_products(request, page, published_products, avail_stores, avail_store_names, avail_liquor_types):
avail_prod_ids = []
for p in avail_stores:
for k in published_products:
if p == k.store:
avail_prod_ids.append(k.id)
products = Product.objects.filter(id__in=avail_prod_ids)
sort_options = [(slugify(option[0]), option[1])
for option in settings.SHOP_PRODUCT_SORT_OPTIONS]
sort_by = request.GET.get("sort", sort_options[0][1])
products = paginate(products.order_by(sort_by),
request.GET.get("page", 1),
settings.SHOP_PER_PAGE_CATEGORY,
settings.MAX_PAGING_LINKS)
products.sort_by = sort_by
sub_categories = [p.titles for p in page.category.children.published()]
avail_stores = list(set(sub_categories) & set(avail_store_names))
avail_liquors = list(set(sub_categories) & set(avail_liquor_types))
avail_categories = avail_liquors + avail_stores
child_categories = Category.objects.filter(titles__in=avail_categories)
return products, child_categories
开发者ID:obsjames,项目名称:md-production-public,代码行数:27,代码来源:checkout.py
示例7: search
def search(request, template="search_results.html", extra_context=None):
"""
Display search results. Takes an optional "contenttype" GET parameter
in the form "app-name.ModelName" to limit search results to a single model.
"""
settings.use_editable()
query = request.GET.get("q", "")
page = request.GET.get("page", 1)
per_page = settings.SEARCH_PER_PAGE
max_paging_links = settings.MAX_PAGING_LINKS
try:
parts = request.GET.get("type", "").split(".", 1)
search_model = apps.get_model(*parts)
search_model.objects.search # Attribute check
except (ValueError, TypeError, LookupError, AttributeError):
search_model = Displayable
search_type = _("Everything")
else:
search_type = search_model._meta.verbose_name_plural.capitalize()
results = search_model.objects.search(query, for_user=request.user)
paginated = paginate(results, page, per_page, max_paging_links)
context = {"query": query, "results": paginated,
"search_type": search_type}
context.update(extra_context or {})
return render(request, template, context)
开发者ID:aagarg,项目名称:mezzanine,代码行数:25,代码来源:views.py
示例8: frontpage
def frontpage(request):
# @TODO: Use weight and featured fields, which need to be implemented.
articles = Article.objects.filter(public=True).order_by('-updated_at')[:5]
articles = paginate(articles, request.GET.get("page", 1),
settings.BLOG_POST_PER_PAGE,
settings.MAX_PAGING_LINKS)
return render(request, ['frontpage.html'], {'articles': articles})
开发者ID:bericht,项目名称:bericht,代码行数:7,代码来源:views.py
示例9: comment_thread
def comment_thread(context, parent):
"""
Return a list of child comments for the given parent, storing all
comments in a dict in the context when first called, using parents
as keys for retrieval on subsequent recursive calls from the
comments template.
"""
if "all_comments" not in context:
comments = defaultdict(list)
if "request" in context and context["request"].user.is_staff:
comments_queryset = parent.comments.all()
else:
comments_queryset = parent.comments.visible()
for comment in comments_queryset.select_related("user"):
comments[comment.replied_to_id].append(comment)
context["all_comments"] = comments
parent_id = parent.id if isinstance(parent, Review) else None
try:
replied_to = int(context["request"].POST["replied_to"])
except KeyError:
replied_to = 0
page = context['request'].GET.get("page", 1)
per_page = django_settings.REVIEWS_PER_PAGE
max_paging_links = django_settings.MAX_PAGING_LINKS
comments_queryset = context["all_comments"].get(parent_id, [])
paginated = paginate(comments_queryset, page, per_page, max_paging_links)
context.update({
"comments_for_thread": paginated,
"no_comments": parent_id is None and not context["all_comments"],
"replied_to": replied_to,
})
return context
开发者ID:saumishr,项目名称:mezzanine,代码行数:35,代码来源:comment_tags.py
示例10: blog_post_list
def blog_post_list(request, tag=None, year=None, month=None, username=None,
category=None, template="blog/blog_post_list.html"):
"""
Display a list of blog posts.
"""
settings.use_editable()
blog_posts = BlogPost.objects.published(for_user=request.user)
if tag is not None:
tag = get_object_or_404(Keyword, slug=tag)
blog_posts = blog_posts.filter(keywords=tag)
if year is not None:
blog_posts = blog_posts.filter(publish_date__year=year)
if month is not None:
blog_posts = blog_posts.filter(publish_date__month=month)
month = month_name[int(month)]
if category is not None:
category = get_object_or_404(BlogCategory, slug=category)
blog_posts = blog_posts.filter(categories=category)
author = None
if username is not None:
author = get_object_or_404(User, username=username)
blog_posts = blog_posts.filter(user=author)
blog_posts = paginate(blog_posts, request.GET.get("page", 1),
settings.BLOG_POST_PER_PAGE,
settings.BLOG_POST_MAX_PAGING_LINKS)
context = {"blog_posts": blog_posts, "year": year, "month": month,
"tag": tag, "category": category, "author": author,
"use_disqus": bool(settings.COMMENTS_DISQUS_SHORTNAME),
"blog_page": blog_page()}
return render_to_response(template, context, RequestContext(request))
开发者ID:MechanisM,项目名称:mezzanine,代码行数:30,代码来源:views.py
示例11: render_blog
def render_blog(self, request, year=None, month=None, author=None, category=None):
posts = self.posts.published(for_user=request.user)
#if tag is not None:
# tag = get_object_or_404(Keyword, slug=tag)
# blog_posts = blog_posts.filter(keywords=tag)
if year is not None:
if not year.isdigit():
raise Http404
posts = posts.filter(publish_date__year=year)
if month is not None:
if not month.isdigit():
raise Http404
posts = posts.filter(publish_date__month=month)
month = month_name[int(month)]
if category is not None:
try:
category = self.categories.get(slug=category)
except Category.DoesNotExist:
raise Http404
posts = posts.filter(category=category)
if author is not None:
author = get_object_or_404(User, username=author)
posts = posts.filter(user=author)
posts = paginate(posts,
request,
self.posts_per_page,
self.max_paging_links)
context = {"displayable": self,
"posts": posts,
"year": year,
"month": month,
"category": category,
"author": author,
}
return HttpResponse(self.get_template().render(RequestContext(request, context)))
开发者ID:iciclespider,项目名称:mezzanine,代码行数:35,代码来源:models.py
示例12: agents
def agents(request, agent_state_slug, agent_city_slug):
agents = queryset_iterator(Agent.objects.filter(slugged_state=abbreviate_slugged_state(agent_state_slug),
slugged_city=agent_city_slug))
# agents = get_list_or_404(Agent, slugged_state=abbreviate_slugged_state(agent_state_slug),
# slugged_city=agent_city_slug)
agent_list = []
for ag in agents:
agent_list.append(ag)
agents = paginate(agent_list,
request.GET.get("page", 1),
100, 10)
profile_claimed = is_profile_claimed(request.user)
if request.GET.get("page") == '1':
return HttpResponsePermanentRedirect(reverse('agent.views.agents',
args=[agent_state_slug, agent_city_slug]))
return render_to_response('pages/agents.html',
{'agents': agents,
'agent_state_slug': agent_state_slug,
'agent_city_slug': agent_city_slug,
'profile_claimed': profile_claimed}, context_instance=RequestContext(request))
开发者ID:mmansour,项目名称:VBA,代码行数:25,代码来源:views.py
示例13: bookmarks
def bookmarks(request, slug=None, username=None):
bookmarks = Bookmark.objects.all().order_by("-publish_date")
keyword = None
user = None
if slug:
try:
keyword = Keyword.objects.get(slug=slug)
except Keyword.DoesNotExist:
raise Http404
bookmarks = bookmarks.filter(keywords__keyword_id=keyword.pk)
if username:
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise Http404
bookmarks = bookmarks.filter(user__username=username)
bookmarks = paginate(
bookmarks,
request.GET.get("page", 1),
15,
settings.MAX_PAGING_LINKS,
)
return render(request, ["bookmarks/bookmarks.html"], {
"bookmarks": bookmarks,
"tag": keyword,
"username": user,
})
开发者ID:adieu,项目名称:mezzanine-bookmarks,代码行数:32,代码来源:views.py
示例14: get_context_data
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['testimonials'] = paginate(context['testimonials'],
self.request.GET.get("page", 1),
5,
settings.MAX_PAGING_LINKS)
return context
开发者ID:pwhipp,项目名称:pwc,代码行数:7,代码来源:views.py
示例15: search
def search(request, template="search_results.html"):
"""
Display search results. Takes an optional "contenttype" GET parameter
in the form "app-name.ModelName" to limit search results to a single model.
"""
settings.use_editable()
query = request.GET.get("q", "")
page = request.GET.get("page", 1)
per_page = settings.SEARCH_PER_PAGE
max_paging_links = settings.MAX_PAGING_LINKS
table_name = BlogPost._meta.db_table
try:
search_model = get_model(*request.GET.get("type", "").split(".", 1))
if not issubclass(search_model, Displayable):
raise TypeError
except TypeError:
search_model = BlogPost#Displayable
search_type = _("blog.BlogPost")#_("Everything")
else:
search_type = search_model._meta.verbose_name_plural.capitalize()
queryWithQuotes = '"%s"' % query
results = search_model.objects.search(queryWithQuotes, for_user=request.user)
filters = request.GET.get("filter", '')
filter_arr = []
if filters != '':
filter_arr = filters.split('-')
filter_sum = ''
if len(filter_arr) > 0:
for i in range(len(filter_arr)):
if is_valid_search_filter(filter_arr[i]):
if i == 0:
filter_sum += filter_arr[i].lower()+'_average'
else:
filter_sum += '+' + filter_arr[i].lower()+'_average'
if filter_sum != '':
'''
If filters are apllied, order vendors by sum of the filter parameter values.
In case filter values are equal, order them as per their overall average.
For now tie between equal overall_average is not broken. To break add more parameters ahead in order of priority.
'''
results = results.extra(select={'filtersum': filter_sum,
'fieldsum':'price_average + website_ex_average + quality_average + service_average',
'followers': 'SELECT COUNT(*) FROM %s WHERE target_blogpost_id=%s.id' % (Follow._meta.db_table, table_name)},
order_by=('-filtersum', '-overall_average', '-fieldsum', '-comments_count', '-followers',)).distinct()
else:
'''
In absence of any filters, order vendors by overall_average by default.
'''
results = results.extra(select={'fieldsum':'price_average + website_ex_average + quality_average + service_average',
'followers': 'SELECT COUNT(*) FROM %s WHERE target_blogpost_id=%s.id' % (Follow._meta.db_table, table_name)},
order_by=('-overall_average', '-fieldsum', '-comments_count', '-followers',)).distinct()
#results.sort(searchComparator, reverse=True)
paginated = paginate(results, page, per_page, max_paging_links)
context = {"query": query, "results": paginated,
"search_type": search_type}
return render(request, template, context)
开发者ID:vadhawal,项目名称:mezzanine,代码行数:59,代码来源:views.py
示例16: comment_thread_social_level2
def comment_thread_social_level2(context, parent):
"""
Return a list of child comments for the given parent, storing all
comments in a dict in the context when first called, using parents
as keys for retrieval on subsequent recursive calls from the
comments template.
"""
comments = None
if "request" in context and context["request"].user.is_staff:
comments_queryset = parent.comments.all()
else:
comments_queryset = parent.comments.visible()
#user_social_auth_list = context["request"].user.social_auth.filter(provider="facebook")
#if not user_social_auth_list:
# user_social_auth_list = context["request"].user.social_auth.filter(provider="twitter")
#if user_social_auth_list:
# user_social_auth = user_social_auth_list[0]
# if user_social_auth:
# friends_of_friends = cache.get(user_social_auth.user.username+"SocialFriendListLevel2")
# if not friends_of_friends:
# friends = SocialFriendList.objects.existing_social_friends(context["request"].user.social_auth.filter(provider="facebook")[0])
# friends_of_friends = list(friends)
# for friend in friends:
# friends_level2 = SocialFriendList.objects.existing_social_friends(friend.social_auth.filter(provider="facebook")[0])
# friends_of_friends = list(chain(friends_of_friends, friends_level2))
# cache.set(user_social_auth.user.username+"SocialFriendListLevel2", friends_of_friends)
friends_of_friends = set()
friends = context["request"].user.relationships.following()
for friend in friends:
friends_of_friends.add(friend)
friends_level2 = friend.relationships.following()
for friend_level2 in friends_level2:
friends_of_friends.add(friend_level2)
comments_queryset = comments_queryset.order_by('-submit_date')
comments = comments_queryset.select_related("user").filter(user__in=friends_of_friends)
parent_id = parent.id if isinstance(parent, Review) else None
try:
replied_to = int(context["request"].POST["replied_to"])
except KeyError:
replied_to = 0
page = context['request'].GET.get("page", 1)
per_page = django_settings.REVIEWS_PER_PAGE
max_paging_links = django_settings.MAX_PAGING_LINKS
paginated = paginate(comments, page, per_page, max_paging_links)
context.update({
"comments_for_thread": paginated,
"no_comments": parent_id is None and not comments,
"replied_to": replied_to,
})
return context
开发者ID:saumishr,项目名称:mezzanine,代码行数:59,代码来源:comment_tags.py
示例17: index
def index(request):
results = CommunityModel.objects.published(for_user=request.user)
result_list = paginate(results, request.GET.get("page", 1), settings.ITEMS_PER_PAGE, settings.MAX_PAGE_LINKS)
return render(request, 'community/index.html', {
'result_list': result_list,
'title': "Community",
})
开发者ID:hachacha,项目名称:rhizome.org,代码行数:8,代码来源:views.py
示例18: list_to_paginate
def list_to_paginate(list_object, request):
"""
Transforma uma lista recebida em objeto para paginação
"""
object_paginate = paginate(list_object, request.GET.get("page", 1),
settings.BLOG_POST_PER_PAGE,
settings.MAX_PAGING_LINKS)
return object_paginate
开发者ID:roberzguerra,项目名称:rover,代码行数:8,代码来源:institutional.py
示例19: get_context_data
def get_context_data(self, **kwargs):
context = super(DocumentDuplicatesView, self).get_context_data(**kwargs)
context['sha_document_list'] = paginate(
self.get_sha_document_list(context['document_list']),
self.request.GET.get("page", 1),
self.mezz_paginate_by,
7)
return context
开发者ID:aaronkyle,项目名称:docmeta,代码行数:8,代码来源:views.py
示例20: community
def community(request, page):
results = CommunityModel.objects.all()
result_list = paginate(results, request.GET.get("page", 1), settings.ITEMS_PER_PAGE, settings.MAX_PAGE_LINKS)
return {
'result_list': result_list,
}
开发者ID:hachacha,项目名称:rhizome.org,代码行数:8,代码来源:page_processors.py
注:本文中的mezzanine.utils.views.paginate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论