本文整理汇总了Python中django.core.paginator.ObjectPaginator.get_page方法的典型用法代码示例。如果您正苦于以下问题:Python ObjectPaginator.get_page方法的具体用法?Python ObjectPaginator.get_page怎么用?Python ObjectPaginator.get_page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.paginator.ObjectPaginator
的用法示例。
在下文中一共展示了ObjectPaginator.get_page方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def get(self, user):
import urllib
user = urllib.unquote(user)
if '@' in user:
u = users.User(user)
else:
u = users.User(user+'@gmail.com')
messages= model.Message.all().filter('user =', u).order('-date').fetch(1000)
if not messages and not users.get_current_user():
raise tornado.web.HTTPError(404)
if not messages and users.get_current_user().email() != u.email():
raise tornado.web.HTTPError(404)
paginator = ObjectPaginator(messages, 10, 1)
try:
page = int(self.get_argument('page', '1'))
except ValueError:
page = 1
try:
records = paginator.get_page(page-1)
except:
records = paginator.get_page(0)
page = 1
self.render('user.html', **{'u':u, 'messages':records, 'paginator':paginator,
"next" : paginator.has_next_page(page-1), 'previous':paginator.has_previous_page(page-1), 'previous_page_number':page-1, 'next_page_number':page+1, "page" : page})
示例2: get_page
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def get_page(self, page_num=None):
try:
if page_num is None:
return ObjectPaginator.get_page(self, self.current_page - 1)
else:
return ObjectPaginator.get_page(self, page_num)
except InvalidPage:
return None
示例3: listMessages
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def listMessages(page=0, page_size=10):
messages = memcache.get("message_list_%s" % (users.get_current_user()))
if not messages:
query = db.GqlQuery("SELECT * FROM Message WHERE namespace_owner = :1 ORDER BY created DESC", users.get_current_user())
messages = query.fetch((page_size * 10))
memcache.set("message_list_%s" % (users.get_current_user()), messages, (60*1))
paginator = ObjectPaginator(messages, page_size)
try:
items = paginator.get_page(page)
except InvalidPage:
raise http.Http404
options = {
"items": items,
"is_paginated": True,
"results_per_page" : page_size,
"has_next": paginator.has_next_page(page),
"has_previous": paginator.has_previous_page(page),
"page": page + 1,
"next": page + 1,
"previous": page - 1,
"pages": paginator.pages,
}
return options
示例4: listNamespaces
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def listNamespaces(page=0, page_size=10):
namespaces = memcache.get("namespace_list")
if not namespaces:
query = db.GqlQuery("SELECT * FROM Namespace WHERE owner = :1", users.get_current_user())
namespaces = query.fetch((page_size * 10))
memcache.set("namespace_list", namespaces, (60*1))
paginator = ObjectPaginator(namespaces, page_size)
try:
items = paginator.get_page(page)
except InvalidPage:
raise http.Http404
options = {
"items": items,
"is_paginated": True,
"results_per_page" : page_size,
"has_next": paginator.has_next_page(page),
"has_previous": paginator.has_previous_page(page),
"page": page + 1,
"next": page + 1,
"previous": page - 1,
"pages": paginator.pages,
}
return options
示例5: list
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def list(request, listing_id):
user = users.GetCurrentUser()
if user is None:
return http.HttpResponseForbidden('You must be signed in to view listing values')
listing_values = None
listing = None
lvs_paginator = None
if request.GET.has_key('page'):
page = int(request.GET['page'])
else:
page = 0
if listing_id:
listing = get_listing(listing_id)
lvs = ListingValue.all().order('-date').filter('listing_key = ', str(listing.key()))
lvs_paginator = ObjectPaginator(lvs, 10)
listing_values = lvs_paginator.get_page(page)
if listing is None or listing_values is None or listing_id is None:
return http.HttpResponseNotFound(
'No values exists for that listing (%r)' %
listing_id)
paginator = {}
paginator['has_previous_page'] = lvs_paginator.has_previous_page(page)
paginator['has_next_page'] = lvs_paginator.has_next_page(page)
paginator['next_page_number'] = page+1
paginator['previous_page_number'] = page-1
return common.respond(request, user,
'values_list',
{'listing': listing,
'listing_values' : listing_values,
'paginator': paginator})
示例6: user_page
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def user_page(request, username):
user = get_object_or_404(User, username=username)
query_set = user.bookmark_set.order_by('-id')
paginator = ObjectPaginator(query_set, ITEM_PER_PAGE)
is_friend = Friendship.objects.filter(
from_friend=request.user,
to_friend=user
)
try:
page = int(request.GET['page'])
except:
page = 1
try:
bookmarks = paginator.get_page(page - 1)
except:
raise Http404
variables = RequestContext(request, {
'bookmarks': bookmarks,
'username': username,
'show_tags': True,
'show_edit': username == request.user.username,
'show_paginator': paginator.pages > 1,
'has_prev': paginator.has_previous_page(page - 1),
'has_next': paginator.has_next_page(page - 1),
'page': page,
'pages': paginator.pages,
'next_page': page + 1,
'prev_page': page - 1,
'is_friend': is_friend
})
return render_to_response('user_page.html', variables)
示例7: get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def get(self,page):
user = users.get_current_user()
if user:
if users.is_current_user_admin():
try:
page = int(page) - 1
except:
page = 0
uploads = Upload.all()
paginator = ObjectPaginator(uploads,10)
if page>=paginator.pages:
page = paginator.pages - 1
pages = range(1,paginator.pages+1)
page_max = len(pages)
template_values = {
'images': paginator.get_page(page),
'user': user,
'pages': pages,
'page_max': page_max,
'page': page+1
}
path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
self.response.out.write(template.render(path, template_values))
else:
template_values = {}
path = os.path.join(os.path.dirname(__file__), 'templates/404.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(users.create_login_url(self.request.uri))
示例8: topics
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def topics(request):
if not request.user.is_authenticated():
return HttpResponseRedirect("/")
# retrieve related topics
user = request.user
topics = Topic.objects.filter(Q(user1=user) | Q(user2=user)).order_by('-update_on')
paginator = ObjectPaginator(topics, 10)
try:
page = int(request.GET.get('page', '1'))
topics = paginator.get_page(page - 1)
except:
page = 1
topics = []
# prepare data to display
messages_command = []
TopicDto = type('TopicDto', (object,), {})
for topicItem in topics:
topicDto = TopicDto()
topicDto.topic = topicItem
topicDto.companion = topicItem.get_companion(user)
topicDto.not_read_messages_count = topicItem.get_count_of_not_read_messages(user)
messages_command.append(topicDto)
page_title = user.get_profile().get_name().encode('utf8') + ' : ' + u'Список приватних повідомлень '.encode('utf8')
return render_to_response('messages/topics.html',
{'pagetitle': page_title,
'u': user.get_profile(), 'can_subscribe': False, 'can_unsubscribe': False,
'page':page, 'paginator':paginator,
'messages_command': messages_command,
'topics': topics},
context_instance=RequestContext(request))
示例9: _get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def _get(self):
upload_url = blobstore.create_upload_url('/image/submit')
page = self.request.get("page")
try:
page = int(page) - 1
except:
page = 0
query = ImageAsset.all().order('-created_at')
images = query.fetch(1000)
if (self.PAGESIZE * page)/1000 > 0:
cursor_iterations = (self.PAGESIZE * page)/1000
for i in range(0, cursor_iterations):
logging.info("Iterating though images %d/%d" % (i,cursor_iterations))
cursor = query.cursor()
query.with_cursor()
images = query.fetch(1000)
paginator = ObjectPaginator(images, self.PAGESIZE)
#if page>=paginator.pages:
# page = paginator.pages - 1
#if page < 0:
# page = 0
self.template_values = {
"images" : paginator.get_page(page),
"pages" : range(page+1,page+paginator.pages+1),
"page" : page+1,
"upload_url" : upload_url
}
self.page_display(self,"templates/gallery.html")
示例10: get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def get(self):
user = self.getAuthentificatedUser()
page = self.request.get('page')
try:
page = int(page) - 1
except:
page = 0
allUsers = self.getUsers().order('login')
paginator = ObjectPaginator(allUsers, 50)
if page >= paginator.pages or page < 0:
page = paginator.pages - 1
if page >= paginator.pages - 1:
next = None
else:
next = page + 2
if page < 1:
prev = None
else:
prev = page
forum = self.getForumInstance()
template_values = {
'url' : users.CreateLogoutURL(self.request.uri),
'user' : user.nickname(),
'forum' : forum,
'users' : paginator.get_page(page),
'pages' : range(1, paginator.pages + 1),
'page' : page+1,
'next' : next,
'prev' : prev,
}
#for user in self.getUsers().order('-login'):
#print user.login
path = os.path.join(os.path.dirname(__file__), os.path.join('templates', 'viewUsers.htm'))
self.response.out.write(template.render(path, template_values))
示例11: get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def get(self):
page = int(self.request.get('page', '0'))
paginator = ObjectPaginator(db.GqlQuery('SELECT * FROM BlogPostModel ORDER BY created DESC'),10)
blogposts = paginator.get_page(page)
nextPageNumber = 0
prevPageNumber = 0
if paginator.has_next_page(page):
nextPageNumber = str(page+1)
if paginator.has_previous_page(page):
prevPageNumber = str(page-1)
template_values = {
'menulinks':menuLinks(),
'blogposts': blogposts,
'user': authenticatedUser(sessions.Session()),
'nextPageNumber': nextPageNumber,
'prevPageNumber': prevPageNumber,
}
path = os.path.join(os.path.dirname(__file__), 'news.html')
self.response.out.write(template.render(path, template_values))
示例12: _run_query
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def _run_query(cls, query, pagination=False, current_page=0, items_per_page=10):
if pagination:
paginator = ObjectPaginator(query, items_per_page)
synopsis_list = paginator.get_page(current_page)
else:
paginator = None
synopsis_list = query
return synopsis_list, paginator
示例13: filtered_kwips_page
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def filtered_kwips_page(request,user_login,year,month=0,day=0,hour=0,serial=0,filter_by='day',with_reply_box=False):
is_single = False
paginate_by = 10
dict = details_for_kwips_page(request,user_login)
month_in_words = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
i=1
for mon in month_in_words:
if month==mon:
month=i
i=i+1
#getting all accounts for user
accounts = Account.objects.filter(user=dict['user'],status=1)
if accounts:
accounts_list_in_csv = queryset_to_csv(accounts,'account')
if filter_by=='year':
quips = Quip.objects.filter(account__in=accounts_list_in_csv,created_at__year=int(year)).order_by('-created_at')
elif filter_by=='month':
quips = Quip.objects.filter(account__in=accounts_list_in_csv,created_at__year=int(year),created_at__month=int(month)).order_by('-created_at')
elif filter_by=='date':
quips = Quip.objects.filter(account__in=accounts_list_in_csv,created_at__year=int(year),created_at__month=int(month),created_at__day=int(day)).order_by('-created_at')
elif filter_by=='hour':
quips = quip_for_a_time(dict['user'],filter_by,year,month,day,hour)
elif filter_by=='minute':
minute=hour[2]+hour[3]
hour = hour[0]+hour[1]
quips = quip_for_a_time(dict['user'],filter_by,year,month,day,int(hour),int(minute))
elif filter_by=='second':
second=hour[4]+hour[5]
minute=hour[2]+hour[3]
hour = hour[0]+hour[1]
quips = quip_for_a_time(dict['user'],filter_by,year,month,day,int(hour),int(minute),int(second))
if len(quips)==1:
is_single=True
elif filter_by=='single':
second=hour[4]+hour[5]
minute=hour[2]+hour[3]
hour = hour[0]+hour[1]
quipsnow = quip_for_a_time(dict['user'],filter_by,year,month,day,int(hour),int(minute),int(second))
is_single=True
for q in quipsnow:
quips = q.quips_on_same_time_serial(int(serial))
#break commented by MD
paginator = ObjectPaginator(quips, paginate_by)
page = int(request.GET.get('page',0))
quips = paginator.get_page(page)
return render_to_response('mypage.html', {'is_paginated': paginator.pages > 1, 'results_per_page': paginate_by,
'has_next': paginator.has_next_page(page), 'has_previous': paginator.has_previous_page(page),
'page': page + 1, 'next': page + 1, 'previous': page - 1, 'pages': paginator.pages, 'is_following': dict['is_following'],'is_following_on_im': dict['is_following_on_im'],
'hits' : paginator.hits, 'login': user_login,'user_profile': dict['user_profile'],'quips': quips,'is_receiver_following':dict['is_receiver_following'],
'users_followees': dict['users_followees'], 'users_followers': dict['users_followers'], 'profile_for_display': dict['profile_for_display'],
'followees_count':dict['followees_count'], 'followers_count':dict['followers_count'],'displayname': dict['displayname'],'favs_count':dict['favs_count'],
'quips_for': 'self','with_reply_box':with_reply_box,'is_single':is_single,
'kwip_count':kwip_count(dict['user']),'comment_count':comment_count(dict['user'])},context_instance=template.RequestContext(request))
示例14: paginate
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def paginate(obj, page):
p = ObjectPaginator(
obj,
PAGE_ELEMENTS
)
try:
obj_list = p.get_page(page - 1)
except InvalidPage:
obj_list = []
return (obj_list, p)
示例15: comments
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import get_page [as 别名]
def comments(request, page):
paginator = ObjectPaginator(Comments.objects.all(), 10)
comments = paginator.get_page(page)
template_parms = {'comment_list': comments, 'comments': True}
if paginator.has_next_page(page):
template_parms['next'] = True
if paginator.has_previous_page(page):
template_parms['prev'] = True
return render_to_response('comments.html', template_parms)