本文整理汇总了Python中misago.core.shortcuts.paginate函数的典型用法代码示例。如果您正苦于以下问题:Python paginate函数的具体用法?Python paginate怎么用?Python paginate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了paginate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, request, thread, page):
try:
thread_model = thread.unwrap()
except AttributeError:
thread_model = thread
posts_queryset = self.get_queryset(request, thread_model)
list_page = paginate(
posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL)
paginator = pagination_dict(list_page, include_page_range=False)
posts = list(list_page.object_list)
posters = []
for post in posts:
post.category = thread.category
post.thread = thread_model
if post.poster:
posters.append(post.poster)
add_acl(request.user, posts)
make_posts_read_aware(request.user, thread_model, posts)
make_users_status_aware(request.user, posters)
if thread.category.acl['can_see_posts_likes']:
add_likes_to_posts(request.user, posts)
self._user = request.user
self.posts = posts
self.paginator = paginator
示例2: list
def list(self, page=0):
queryset = exclude_invisible_threads(
self.user, self.forum, self.forum.thread_set)
queryset = self.filter_threads(queryset)
queryset = queryset.order_by(*self.sort_by)
announcements_qs = queryset.filter(weight=ANNOUNCEMENT)
threads_qs = queryset.filter(weight__lt=ANNOUNCEMENT)
self._page = paginate(threads_qs, page, 20, 10)
self._paginator = self._page.paginator
threads = []
for announcement in announcements_qs:
threads.append(announcement)
for thread in self._page.object_list:
threads.append(thread)
for thread in threads:
thread.forum = self.forum
self.label_threads(threads, self.forum.labels)
self.make_threads_read_aware(threads)
return threads
示例3: list
def list(self, page=0):
queryset = self.get_queryset()
queryset = queryset.order_by(self.sort_by)
pinned_qs = queryset.filter(is_pinned=True)
threads_qs = queryset.filter(is_pinned=False)
self._page = paginate(threads_qs, page, 20, 10)
self._paginator = self._page.paginator
threads = []
if self.fetch_pinned_threads:
for thread in pinned_qs:
threads.append(thread)
self.pinned_count += 1
for thread in self._page.object_list:
threads.append(thread)
for thread in threads:
thread.forum = self.forum
self.label_threads(threads, self.forum.labels)
self.make_threads_read_aware(threads)
return threads
示例4: __init__
def __init__(self, request, category, list_type, page):
self.allow_see_list(request, category, list_type)
base_queryset = self.get_base_queryset(request, category.categories, list_type)
threads_categories = [category.category] + category.subcategories
threads_queryset = self.get_remaining_threads_queryset(base_queryset, category.category, threads_categories)
list_page = paginate(threads_queryset, page, settings.MISAGO_THREADS_PER_PAGE, settings.MISAGO_THREADS_TAIL)
paginator = pagination_dict(list_page, include_page_range=False)
if list_page.number > 1:
threads = list(list_page.object_list)
else:
pinned_threads = list(self.get_pinned_threads(base_queryset, category.category, threads_categories))
threads = list(pinned_threads) + list(list_page.object_list)
if list_type in ('new', 'unread'):
# we already know all threads on list are unread
threadstracker.make_unread(threads)
else:
threadstracker.make_threads_read_aware(request.user, threads)
add_categories_to_threads(category.category, category.categories, threads)
add_acl(request.user, threads)
make_subscription_aware(request.user, threads)
# set state on object for easy access from hooks
self.category = category
self.threads = threads
self.list_type = list_type
self.paginator = paginator
示例5: warnings
def warnings(request, profile, page=0):
warnings_qs = profile.warnings.order_by('-id')
warnings = paginate(warnings_qs, page, 5, 2)
items_left = warnings.paginator.count - warnings.end_index()
add_acl(request.user, warnings.object_list)
warning_level = get_user_warning_level(profile)
warning_level_obj = get_user_warning_obj(profile)
active_warnings = warning_level - warnings.start_index() + 1
for warning in warnings.object_list:
if warning.is_canceled:
warning.is_active = False
else:
warning.is_active = active_warnings > 0
active_warnings -= 1
levels_total = len(get_warning_levels()) - 1
if levels_total and warning_level:
warning_progress = 100 - warning_level * 100 / levels_total
else:
warning_progress = 100
if warning_level:
warning_level_obj.level = warning_level
return render(request, 'misago/profile/warnings.html', {
'profile': profile,
'warnings': warnings,
'warning_level': warning_level_obj,
'warning_progress': warning_progress,
'page_number': warnings.number,
'items_left': items_left
})
示例6: __init__
def __init__(self, request, thread, page):
posts_queryset = self.get_queryset(request, thread.model)
list_page = paginate(posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL)
paginator = pagination_dict(list_page, include_page_range=False)
posts = list(list_page.object_list)
posters = []
for post in posts:
post.category = thread.category
post.thread = thread.model
if post.poster:
posters.append(post.poster)
add_acl(request.user, posts)
make_posts_read_aware(request.user, thread.model, posts)
make_users_status_aware(request.user, posters)
self._user = request.user
self.posts = posts
self.paginator = paginator
示例7: rank
def rank(request, rank_slug, page=0):
rank = get_object_or_404(Rank.objects.filter(is_tab=True), slug=rank_slug)
queryset = rank.user_set.select_related('rank').order_by('slug')
page = paginate(queryset, page, settings.MISAGO_USERS_PER_PAGE, 4)
paginator = pagination_dict(page)
request.frontend_context['USERS'] = dict(
results=UserSerializer(page.object_list, many=True).data,
**paginator
)
if rank.description:
description = {
'plain': rank.description,
'html': format_plaintext_for_html(rank.description)
}
else:
description = None
template = "misago/userslists/rank.html"
return render(request, template, {
'rank': rank,
'users': page.object_list,
'paginator': paginator
})
示例8: get_threads
def get_threads(self, request, kwargs):
queryset = self.get_threads_queryset(request, forum)
queryset = threads_qs.order_by('-last_post_id')
page = paginate(threads_qs, kwargs.get('page', 0), 30, 10)
threads = [thread for thread in page.object_list]
return page, threads
示例9: test_paginated_response_data_serializer
def test_paginated_response_data_serializer(request):
data = [0, 1, 2, 3]
page = paginate(data, 0, 10)
return paginated_response(
page,
data=['a', 'b', 'c', 'd'],
serializer=MockSerializer,
)
示例10: __init__
def __init__(self, request, thread, page):
try:
thread_model = thread.unwrap()
except AttributeError:
thread_model = thread
posts_queryset = self.get_posts_queryset(request, thread_model)
posts_limit = settings.MISAGO_POSTS_PER_PAGE
posts_orphans = settings.MISAGO_POSTS_TAIL
list_page = paginate(
posts_queryset, page, posts_limit, posts_orphans, paginator=PostsPaginator
)
paginator = pagination_dict(list_page)
posts = list(list_page.object_list)
posters = []
for post in posts:
post.category = thread.category
post.thread = thread_model
if post.poster:
posters.append(post.poster)
make_users_status_aware(request.user, posters)
if thread.category.acl['can_see_posts_likes']:
add_likes_to_posts(request.user, posts)
# add events to posts
if thread_model.has_events:
first_post = None
if list_page.has_previous():
first_post = posts[0]
last_post = None
if list_page.has_next():
last_post = posts[-1]
events_limit = settings.MISAGO_EVENTS_PER_PAGE
posts += self.get_events_queryset(
request, thread_model, events_limit, first_post, last_post
)
# sort both by pk
posts.sort(key=lambda p: p.pk)
# make posts and events ACL and reads aware
add_acl(request.user, posts)
make_posts_read_aware(request.user, thread_model, posts)
self._user = request.user
self.posts = posts
self.paginator = paginator
示例11: name_history
def name_history(request, profile, page=0):
name_changes_qs = profile.namechanges.all().order_by('-id')
name_changes = paginate(name_changes_qs, page, 12, 4)
items_left = name_changes.paginator.count - name_changes.end_index()
return render(request, 'misago/profile/name_history.html', {
'profile': profile,
'name_changes': name_changes,
'page_number': name_changes.number,
'items_left': items_left
})
示例12: test_paginated_response_data_extra
def test_paginated_response_data_extra(request):
data = [0, 1, 2, 3]
page = paginate(data, 0, 10)
return paginated_response(
page,
data=['a', 'b', 'c', 'd'],
extra={
'next': 'EXTRA',
'lorem': 'ipsum',
},
)
示例13: get_posts
def get_posts(self, user, forum, thread, kwargs):
queryset = self.get_posts_queryset(user, forum, thread)
page = paginate(queryset, kwargs.get('page', 0), 10, 5)
posts = []
for post in page.object_list:
add_acl(user, post)
if post.poster:
poster_state = get_user_state(post.poster, user.acl)
post.poster.online_state = poster_state
posts.append(post)
return page, posts
示例14: follows
def follows(request, profile, page=0):
followers_qs = profile.follows.order_by('slug')
followers = paginate(followers_qs, page, 6 * 4, 6)
items_left = followers.paginator.count - followers.end_index()
if followers.paginator.count != profile.following:
profile.following = followers.paginator.count
profile.save(update_fields=['following'])
return render(request, 'misago/profile/follows.html', {
'profile': profile,
'followers': followers,
'items_left': items_left,
})
示例15: follows
def follows(request, profile):
queryset = profile.follows.select_related('rank').order_by('slug')
page = paginate(queryset, None, settings.MISAGO_USERS_PER_PAGE, 4)
paginator = pagination_dict(page)
request.frontend_context['PROFILE_FOLLOWS'] = dict(
results=UserSerializer(page.object_list, many=True).data,
**paginator
)
return render(request, 'misago/profile/follows.html', {
'profile': profile,
'follows': page.object_list,
})