本文整理汇总了Python中sumo.utils.paginate函数的典型用法代码示例。如果您正苦于以下问题:Python paginate函数的具体用法?Python paginate怎么用?Python paginate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了paginate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _answers_data
def _answers_data(request, question_id, form=None, watch_form=None, answer_preview=None):
"""Return a map of the minimal info necessary to draw an answers page."""
question = get_object_or_404(Question, pk=question_id)
answers_ = paginate(request, question.answers.all(), per_page=constants.ANSWERS_PER_PAGE)
vocab = [t.name for t in Tag.objects.all()] # TODO: Fetch only name.
feed_urls = (
(reverse("questions.answers.feed", kwargs={"question_id": question_id}), AnswersFeed().title(question)),
)
frequencies = dict(FREQUENCY_CHOICES)
is_watching_question = request.user.is_authenticated() and (
QuestionReplyEvent.is_notifying(request.user, question)
or QuestionSolvedEvent.is_notifying(request.user, question)
)
return {
"question": question,
"answers": answers_,
"form": form or AnswerForm(),
"answer_preview": answer_preview,
"watch_form": watch_form or _init_watch_form(request, "reply"),
"feeds": feed_urls,
"tag_vocab": json.dumps(vocab),
"frequencies": frequencies,
"is_watching_question": is_watching_question,
"can_tag": request.user.has_perm("questions.tag_question"),
"can_create_tags": request.user.has_perm("taggit.add_tag"),
}
开发者ID:fox2mike,项目名称:kitsune,代码行数:27,代码来源:views.py
示例2: locale_discussions
def locale_discussions(request):
locale_name = LOCALES[request.LANGUAGE_CODE].native
threads = Thread.objects.filter(document__locale=request.LANGUAGE_CODE,
document__allow_discussion=True)
try:
sort = int(request.GET.get('sort', 0))
except ValueError:
sort = 0
try:
desc = int(request.GET.get('desc', 0))
except ValueError:
desc = 0
desc_toggle = 0 if desc else 1
threads_ = sort_threads(threads, sort, desc)
# Ignore sticky-ness:
threads_ = threads_.order_by('-last_post__created')
threads_ = paginate(request, threads_,
per_page=kbforums.THREADS_PER_PAGE)
is_watching_locale = (request.user.is_authenticated() and
NewThreadInLocaleEvent.is_notifying(
request.user, locale=request.LANGUAGE_CODE))
return render(request, 'kbforums/discussions.html', {
'locale_name': locale_name, 'threads': threads_,
'desc_toggle': desc_toggle,
'is_watching_locale': is_watching_locale})
开发者ID:LASarkar,项目名称:kitsune,代码行数:28,代码来源:views.py
示例3: _answers_data
def _answers_data(request, question_id, form=None, watch_form=None,
answer_preview=None):
"""Return a map of the minimal info necessary to draw an answers page."""
question = get_object_or_404(Question, pk=question_id)
answers_ = question.answers.all()
if not request.MOBILE:
answers_ = paginate(request, answers_,
per_page=constants.ANSWERS_PER_PAGE)
feed_urls = ((reverse('questions.answers.feed',
kwargs={'question_id': question_id}),
AnswersFeed().title(question)),)
frequencies = dict(FREQUENCY_CHOICES)
is_watching_question = (
request.user.is_authenticated() and (
QuestionReplyEvent.is_notifying(request.user, question) or
QuestionSolvedEvent.is_notifying(request.user, question)))
return {'question': question,
'answers': answers_,
'form': form or AnswerForm(),
'answer_preview': answer_preview,
'watch_form': watch_form or _init_watch_form(request, 'reply'),
'feeds': feed_urls,
'frequencies': frequencies,
'is_watching_question': is_watching_question,
'can_tag': request.user.has_perm('questions.tag_question'),
'can_create_tags': request.user.has_perm('taggit.add_tag')}
开发者ID:victorneo,项目名称:kitsune,代码行数:27,代码来源:views.py
示例4: locale_discussions
def locale_discussions(request):
locale_name = LOCALES[request.locale].native
threads = Thread.objects.filter(document__locale=request.locale, document__allow_discussion=True)
try:
sort = int(request.GET.get("sort", 0))
except ValueError:
sort = 0
try:
desc = int(request.GET.get("desc", 0))
except ValueError:
desc = 0
desc_toggle = 0 if desc else 1
threads_ = sort_threads(threads, sort, desc)
# Ignore sticky-ness:
threads_ = threads_.order_by("-last_post__created")
threads_ = paginate(request, threads_, per_page=kbforums.THREADS_PER_PAGE)
is_watching_locale = request.user.is_authenticated() and NewThreadInLocaleEvent.is_notifying(
request.user, locale=request.locale
)
return jingo.render(
request,
"kbforums/discussions.html",
{
"locale_name": locale_name,
"threads": threads_,
"desc_toggle": desc_toggle,
"is_watching_locale": is_watching_locale,
},
)
开发者ID:georgedorn,项目名称:kitsune,代码行数:32,代码来源:views.py
示例5: threads
def threads(request, forum_slug):
"""View all the threads in a forum."""
forum = get_object_or_404(Forum, slug=forum_slug)
if not forum.allows_viewing_by(request.user):
raise Http404 # Pretend there's nothing there.
try:
sort = int(request.GET.get("sort", 0))
except ValueError:
sort = 0
try:
desc = int(request.GET.get("desc", 0))
except ValueError:
desc = 0
desc_toggle = 0 if desc else 1
threads_ = sort_threads(forum.thread_set, sort, desc)
threads_ = paginate(request, threads_, per_page=constants.THREADS_PER_PAGE)
feed_urls = ((reverse("forums.threads.feed", args=[forum_slug]), ThreadsFeed().title(forum)),)
return jingo.render(
request,
"forums/threads.html",
{"forum": forum, "threads": threads_, "sort": sort, "desc_toggle": desc_toggle, "feeds": feed_urls},
)
开发者ID:MechanisM,项目名称:kitsune,代码行数:27,代码来源:views.py
示例6: threads
def threads(request, document_slug):
"""View all the threads in a discussion forum."""
doc = get_document(document_slug, request)
try:
sort = int(request.GET.get("sort", 0))
except ValueError:
sort = 0
try:
desc = int(request.GET.get("desc", 0))
except ValueError:
desc = 0
desc_toggle = 0 if desc else 1
threads_ = sort_threads(doc.thread_set, sort, desc)
threads_ = paginate(request, threads_, per_page=kbforums.THREADS_PER_PAGE)
feed_urls = ((reverse("wiki.discuss.threads.feed", args=[document_slug]), ThreadsFeed().title(doc)),)
is_watching_forum = request.user.is_authenticated() and NewThreadEvent.is_notifying(request.user, doc)
return jingo.render(
request,
"kbforums/threads.html",
{
"document": doc,
"threads": threads_,
"is_watching_forum": is_watching_forum,
"sort": sort,
"desc_toggle": desc_toggle,
"feeds": feed_urls,
},
)
开发者ID:georgedorn,项目名称:kitsune,代码行数:32,代码来源:views.py
示例7: list_documents
def list_documents(request, category=None, tag=None):
"""List wiki documents."""
docs = Document.objects.filter(locale=request.locale).order_by('title')
if category:
docs = docs.filter(category=category)
try:
category_id = int(category)
except ValueError:
raise Http404
try:
category = unicode(dict(CATEGORIES)[category_id])
except KeyError:
raise Http404
if tag:
tagobj = get_object_or_404(Tag, slug=tag)
default_lang = settings.WIKI_DEFAULT_LANGUAGE
if request.locale == default_lang:
docs = docs.filter(tags__name=tagobj.name)
else:
# blows up: docs = docs.filter(parent__tags__name=tagobj.name)
parent_ids = Document.objects.filter(
locale=default_lang, tags__name=tagobj.name) \
.values_list('id', flat=True)
docs = docs.filter(parent__in=parent_ids)
docs = paginate(request, docs, per_page=DOCUMENTS_PER_PAGE)
return jingo.render(request, 'wiki/list_documents.html',
{'documents': docs,
'category': category,
'tag': tag})
开发者ID:fox2mike,项目名称:kitsune,代码行数:31,代码来源:views.py
示例8: threads
def threads(request, document_slug):
"""View all the threads in a discussion forum."""
doc = get_document(document_slug, request)
try:
sort = int(request.GET.get('sort', 0))
except ValueError:
sort = 0
try:
desc = int(request.GET.get('desc', 0))
except ValueError:
desc = 0
desc_toggle = 0 if desc else 1
threads_ = sort_threads(doc.thread_set, sort, desc)
threads_ = paginate(request, threads_,
per_page=kbforums.THREADS_PER_PAGE)
feed_urls = ((reverse('wiki.discuss.threads.feed', args=[document_slug]),
ThreadsFeed().title(doc)),)
is_watching_forum = (request.user.is_authenticated() and
NewThreadEvent.is_notifying(request.user, doc))
return jingo.render(request, 'kbforums/threads.html',
{'document': doc, 'threads': threads_,
'is_watching_forum': is_watching_forum,
'sort': sort, 'desc_toggle': desc_toggle,
'feeds': feed_urls})
开发者ID:GPHemsley,项目名称:kuma,代码行数:28,代码来源:views.py
示例9: posts
def posts(request, forum_slug, thread_id, form=None, reply_preview=None):
"""View all the posts in a thread."""
forum = get_object_or_404(Forum, slug=forum_slug)
if not forum.allows_viewing_by(request.user):
raise Http404
thread = get_object_or_404(Thread, pk=thread_id, forum=forum)
posts_ = thread.post_set.all()
count = posts_.count()
posts_ = posts_.select_related('author', 'updated_by')
posts_ = posts_.extra(
select={'author_post_count': 'SELECT COUNT(*) FROM forums_post WHERE '
'forums_post.author_id = auth_user.id'})
posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count)
if not form:
form = ReplyForm()
feed_urls = ((reverse('forums.posts.feed',
kwargs={'forum_slug': forum_slug,
'thread_id': thread_id}),
PostsFeed().title(thread)),)
is_watching_thread = (request.user.is_authenticated() and
NewPostEvent.is_notifying(request.user, thread))
return jingo.render(request, 'forums/posts.html',
{'forum': forum, 'thread': thread,
'posts': posts_, 'form': form,
'reply_preview': reply_preview,
'is_watching_thread': is_watching_thread,
'feeds': feed_urls,
'forums': Forum.objects.all()})
开发者ID:Sancus,项目名称:kitsune,代码行数:33,代码来源:views.py
示例10: test_invalid_page_param
def test_invalid_page_param():
url = '%s?%s' % (reverse('search'), 'page=a')
request = test_utils.RequestFactory().get(url)
queryset = range(100)
paginated = paginate(request, queryset)
eq_(paginated.url,
request.build_absolute_uri(request.path) + '?')
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:7,代码来源:test_pagination.py
示例11: gallery
def gallery(request, media_type="image"):
"""The media gallery.
Filter can be set to 'images' or 'videos'.
"""
if media_type == "image":
media_qs = Image.objects.filter(locale=request.locale)
elif media_type == "video":
media_qs = Video.objects.filter(locale=request.locale)
else:
raise Http404
media = paginate(request, media_qs, per_page=ITEMS_PER_PAGE)
drafts = _get_drafts(request.user)
image_form, video_form, upload_type_form = _init_forms(request, drafts)
return jingo.render(
request,
"gallery/gallery.html",
{
"media": media,
"media_type": media_type,
"upload_type_form": upload_type_form,
"image_form": image_form,
"video_form": video_form,
},
)
开发者ID:erikrose,项目名称:kitsune,代码行数:29,代码来源:views.py
示例12: posts
def posts(request, forum_slug, thread_id, form=None, reply_preview=None):
"""View all the posts in a thread."""
forum = get_object_or_404(Forum, slug=forum_slug)
if not forum.allows_viewing_by(request.user):
raise Http404
thread = get_object_or_404(Thread, pk=thread_id, forum=forum)
posts_ = paginate(request, thread.post_set.all(),
constants.POSTS_PER_PAGE)
if not form:
form = ReplyForm()
feed_urls = ((reverse('forums.posts.feed',
kwargs={'forum_slug': forum_slug,
'thread_id': thread_id}),
PostsFeed().title(thread)),)
is_watching_thread = (request.user.is_authenticated() and
NewPostEvent.is_notifying(request.user, thread))
return jingo.render(request, 'forums/posts.html',
{'forum': forum, 'thread': thread,
'posts': posts_, 'form': form,
'reply_preview': reply_preview,
'is_watching_thread': is_watching_thread,
'feeds': feed_urls,
'forums': Forum.objects.all()})
开发者ID:GPHemsley,项目名称:kuma,代码行数:28,代码来源:views.py
示例13: list_documents
def list_documents(request, category=None, topic=None):
"""List wiki documents."""
docs = Document.objects.filter(locale=request.LANGUAGE_CODE).order_by('title')
if category:
docs = docs.filter(category=category)
try:
category_id = int(category)
except ValueError:
raise Http404
try:
category = unicode(dict(CATEGORIES)[category_id])
except KeyError:
raise Http404
if topic:
topic = get_object_or_404(Topic, slug=topic)
default_lang = settings.WIKI_DEFAULT_LANGUAGE
if request.LANGUAGE_CODE == default_lang:
docs = docs.filter(topics=topic)
else:
parent_ids = Document.objects.filter(
locale=default_lang, topics=topic).values_list('id', flat=True)
docs = docs.filter(parent__in=parent_ids)
docs = paginate(request, docs, per_page=DOCUMENTS_PER_PAGE)
return render(request, 'wiki/list_documents.html', {
'documents': docs,
'category': category,
'topic': topic.title if topic else None})
开发者ID:LASarkar,项目名称:kitsune,代码行数:29,代码来源:views.py
示例14: posts
def posts(request, forum_slug, thread_id, form=None, reply_preview=None):
"""View all the posts in a thread."""
forum = get_object_or_404(Forum, slug=forum_slug)
if not forum.allows_viewing_by(request.user):
raise Http404
thread = get_object_or_404(Thread, pk=thread_id, forum=forum)
posts_ = paginate(request, thread.post_set.all(), constants.POSTS_PER_PAGE)
if not form:
form = ReplyForm()
feed_urls = (
(
reverse("forums.posts.feed", kwargs={"forum_slug": forum_slug, "thread_id": thread_id}),
PostsFeed().title(thread),
),
)
return jingo.render(
request,
"forums/posts.html",
{
"forum": forum,
"thread": thread,
"posts": posts_,
"form": form,
"reply_preview": reply_preview,
"feeds": feed_urls,
"forums": Forum.objects.all(),
},
)
开发者ID:MechanisM,项目名称:kitsune,代码行数:33,代码来源:views.py
示例15: gallery_async
def gallery_async(request):
"""AJAX endpoint to media gallery.
Returns an HTML list representation of the media.
"""
# Maybe refactor this into existing views and check request.is_ajax?
media_type = request.GET.get('type', 'image')
term = request.GET.get('q')
if media_type == 'image':
media_qs = Image.objects
elif media_type == 'video':
media_qs = Video.objects
else:
raise Http404
if request.LANGUAGE_CODE == settings.WIKI_DEFAULT_LANGUAGE:
media_qs = media_qs.filter(locale=request.LANGUAGE_CODE)
else:
locales = [request.LANGUAGE_CODE, settings.WIKI_DEFAULT_LANGUAGE]
media_qs = media_qs.filter(locale__in=locales)
if term:
media_qs = media_qs.filter(Q(title__icontains=term) |
Q(description__icontains=term))
media = paginate(request, media_qs, per_page=ITEMS_PER_PAGE)
return jingo.render(request, 'gallery/includes/media_list.html',
{'media_list': media})
开发者ID:bajubullet,项目名称:kitsune,代码行数:30,代码来源:views.py
示例16: threads
def threads(request, forum_slug):
"""View all the threads in a forum."""
forum = get_object_or_404(Forum, slug=forum_slug)
if not forum.allows_viewing_by(request.user):
raise Http404 # Pretend there's nothing there.
try:
sort = int(request.GET.get('sort', 0))
except ValueError:
sort = 0
try:
desc = int(request.GET.get('desc', 0))
except ValueError:
desc = 0
desc_toggle = 0 if desc else 1
threads_ = sort_threads(forum.thread_set, sort, desc)
count = threads_.count()
threads_ = threads_.select_related('creator', 'last_post',
'last_post__author')
threads_ = paginate(request, threads_,
per_page=constants.THREADS_PER_PAGE, count=count)
feed_urls = ((reverse('forums.threads.feed', args=[forum_slug]),
ThreadsFeed().title(forum)),)
is_watching_forum = (request.user.is_authenticated() and
NewThreadEvent.is_notifying(request.user, forum))
return jingo.render(request, 'forums/threads.html',
{'forum': forum, 'threads': threads_,
'is_watching_forum': is_watching_forum,
'sort': sort, 'desc_toggle': desc_toggle,
'feeds': feed_urls})
开发者ID:Sancus,项目名称:kitsune,代码行数:34,代码来源:views.py
示例17: test_paginator_filter
def test_paginator_filter():
# Correct number of <li>s on page 1.
url = reverse('search')
request = test_utils.RequestFactory().get(url)
pager = paginate(request, range(100), per_page=9)
html = paginator(pager)
doc = pyquery.PyQuery(html)
eq_(11, len(doc('li')))
# Correct number of <li>s in the middle.
url = '%s?%s' % (reverse('search'), 'page=10')
request = test_utils.RequestFactory().get(url)
pager = paginate(request, range(200), per_page=10)
html = paginator(pager)
doc = pyquery.PyQuery(html)
eq_(13, len(doc('li')))
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:17,代码来源:test_pagination.py
示例18: test_paginated_url
def test_paginated_url():
"""Avoid duplicating page param in pagination."""
url = '%s?%s' % (reverse('search'), 'q=bookmarks&page=2')
request = test_utils.RequestFactory().get(url)
queryset = [{}, {}]
paginated = paginate(request, queryset)
eq_(paginated.url,
request.build_absolute_uri(request.path) + '?q=bookmarks')
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:8,代码来源:test_pagination.py
示例19: history
def history(request, pk):
key = get_object_or_404(Key, pk=pk)
if key.user != request.user:
raise PermissionDenied
items = key.history.all().order_by('-pk')
items = paginate(request, items, per_page=ITEMS_PER_PAGE)
return jingo.render(request, 'authkeys/history.html',
dict(key=key, items=items))
开发者ID:GPHemsley,项目名称:kuma,代码行数:8,代码来源:views.py
示例20: revisions
def revisions(request):
"""Dashboard for reviewing revisions"""
filter_form = RevisionDashboardForm(request.GET)
page = request.GET.get('page', 1)
revisions = (Revision.objects.select_related('creator')
.order_by('-created')
.defer('content'))
query_kwargs = False
# We can validate right away because no field is required
if filter_form.is_valid():
query_kwargs = {}
query_kwargs_map = {
'user': 'creator__username__istartswith',
'locale': 'document__locale',
'topic': 'slug__icontains',
}
# Build up a dict of the filter conditions, if any, then apply
# them all in one go.
for fieldname, kwarg in query_kwargs_map.items():
filter_arg = filter_form.cleaned_data[fieldname]
if filter_arg:
query_kwargs[kwarg] = filter_arg
start_date = filter_form.cleaned_data['start_date']
if start_date:
end_date = (filter_form.cleaned_data['end_date'] or
datetime.datetime.now())
query_kwargs['created__range'] = [start_date, end_date]
if query_kwargs:
revisions = revisions.filter(**query_kwargs)
total = revisions.count()
else:
# If no filters, just do a straight count(). It's the same
# result, but much faster to compute.
total = Revision.objects.count()
# Only bother with this if we're actually going to get
# some revisions from it. Otherwise it's a pointless but
# potentially complex query.
revisions = paginate(request, revisions, per_page=PAGE_SIZE)
context = {'revisions': revisions, 'page': page, 'total': total}
# Serve the response HTML conditionally upon reques type
if request.is_ajax():
return render(request,
'dashboards/includes/revision_dashboard_body.html',
context)
else:
context['form'] = filter_form
return render(request, 'dashboards/revisions.html', context)
开发者ID:kyoshino,项目名称:kuma,代码行数:58,代码来源:views.py
注:本文中的sumo.utils.paginate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论