本文整理汇总了Python中sumo.utils.paginate函数的典型用法代码示例。如果您正苦于以下问题:Python paginate函数的具体用法?Python paginate怎么用?Python paginate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了paginate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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"),
}
示例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})
示例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')}
示例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,
},
)
示例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},
)
示例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,
},
)
示例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})
示例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})
示例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()})
示例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) + '?')
示例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,
},
)
示例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()})
示例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})
示例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(),
},
)
示例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})