本文整理汇总了Python中django.core.paginator.ObjectPaginator.has_next_page方法的典型用法代码示例。如果您正苦于以下问题:Python ObjectPaginator.has_next_page方法的具体用法?Python ObjectPaginator.has_next_page怎么用?Python ObjectPaginator.has_next_page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.paginator.ObjectPaginator
的用法示例。
在下文中一共展示了ObjectPaginator.has_next_page方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_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))
示例2: get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def get(self, slug):
s = utils.lookup_agency_alias(slug)
if s:
return self.redirect('/agency/%s/' % (s))
agency = utils.get_agency(slug)
if not agency:
raise tornado.web.HTTPError(404)
messages =model.MessageAgency.all().filter('agency', agency).order('-date').fetch(1000)
paginator = ObjectPaginator(messages, 10, 1)
try:
page = int(self.get_argument('page', '1'))
except ValueError:
page = 1
if page <= 0:
page = 1
try:
records = paginator.get_page(page-1)
except:
records = paginator.get_page(0)
page = 1
self.render('agency.html', agency=agency, 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)
示例3: listMessages
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_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 has_next_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 has_next_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 has_next_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: filtered_kwips_page
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_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))
示例8: comments
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_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)
示例9: _display_common
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def _display_common(response_dict, page, p):
paginator = ObjectPaginator(p, 20, 2)
p = paginator.get_page(page)
if not p:
raise Http404
response_dict['object_list'] = p
response_dict['page'] = page
if paginator.has_next_page(page):
response_dict['next'] = page+1
if paginator.has_previous_page(page):
response_dict['prev'] = page-1
return response_dict
示例10: list
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def list(self, request, queryset, page=None):
"""
Renders a list of model objects to HttpResponse.
"""
template_name = '%s/%s_list.html' % (self.template_dir, queryset.model._meta.module_name)
if self.paginate_by:
paginator = ObjectPaginator(queryset, self.paginate_by)
if not page:
page = request.GET.get('page', 1)
try:
page = int(page)
object_list = paginator.get_page(page - 1)
except (InvalidPage, ValueError):
if page == 1 and self.allow_empty:
object_list = []
else:
raise Http404
c = RequestContext(request, {
'%s_list' % self.template_object_name: object_list,
'is_paginated': paginator.pages > 1,
'results_per_page': self.paginate_by,
'has_next': paginator.has_next_page(page - 1),
'has_previous': paginator.has_previous_page(page - 1),
'page': page,
'next': page + 1,
'previous': page - 1,
'last_on_page': paginator.last_on_page(page - 1),
'first_on_page': paginator.first_on_page(page - 1),
'pages': paginator.pages,
'hits' : paginator.hits,
}, self.context_processors)
else:
object_list = queryset
c = RequestContext(request, {
'%s_list' % self.template_object_name: object_list,
'is_paginated': False
}, self.context_processors)
if not self.allow_empty and len(queryset) == 0:
raise Http404
# Hide unexposed fields
for obj in object_list:
self._hide_unexposed_fields(obj, self.expose_fields)
c.update(self.extra_context)
t = self.template_loader.get_template(template_name)
return HttpResponse(t.render(c), mimetype=self.mimetype)
示例11: main
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def main(request,fb_for='all'):
if request.user.is_superuser:
page = int(request.GET.get('page',0))
paginate_by = 10
if fb_for=='self':
feedback = Feedback.objects.filter(user=request.user).order_by('-created_at')
elif fb_for=='all':
feedback = Feedback.objects.all().order_by('-created_at')
paginator = ObjectPaginator(feedback, paginate_by)
feedback = paginator.get_page(page)
return render_to_response('fb.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,
'hits' : paginator.hits,'quips': feedback,'quips_for': fb_for,},
context_instance=template.RequestContext(request))
else:
return HttpResponseRedirect('/'+request.user.username+'/')
#sweating by still coding :)
示例12: everyones_kwips
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def everyones_kwips(request):
from django.db import connection
cursor = connection.cursor()
page = int(request.GET.get('page',0))
paginate_by = 10
quips_for ='everyone'
if request.user.is_authenticated():
user_login=request.user.username
else:
user_login = 'kwippy'
# cursor.execute("select kwippy_quip.id from kwippy_quip,kwippy_account where kwippy_account.id=kwippy_quip.account_id and kwippy_quip.repeat_id in (kwippy_quip.id,0) and kwippy_quip.formated not in ('Away','Available','Logged Out') and kwippy_account.user_id>0 order by id desc limit 1000")
cursor.execute("select id from kwippy_quip where repeat_id in (id,0) and formated not in ('Away','Available','Logged Out')and account_id in (select id from kwippy_account where status=1 and user_id>0) order by id desc limit 1000")
quip_ids = [item[0] for item in cursor.fetchall()]
quips = Quip.objects.filter(id__in=quip_ids).order_by('-created_at')
#cursor.execute(
#"select distinct(account_id) from kwippy_quip order by id desc limit 100")
##"select distinct(q.account_id) from kwippy_quip q, kwippy_account a where a.id=q.account_id and a.user_id>1 order by q.created_at desc limit 100")
#account_ids = [int(item[0]) for item in cursor.fetchall()]
#quips = Quip.objects.filter(id=0)
#for acc_id in account_ids:
#cursor.execute("select * from kwippy_quip where account_id = %d order by created_at desc limit 1" % (acc_id))
#quip_id = [item[0] for item in cursor.fetchall()]
#kwip = Quip.objects.filter(id=int(quip_id[0]))
#quips = quips | kwip
#quips = quips.order_by('-created_at')
#quips = Quip.objects.all().exclude(original='I'm not here right now').order_by('-created_at')[:100]
dict = details_for_kwips_page(request,user_login)
paginator = ObjectPaginator(quips, paginate_by)
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,
'hits' : paginator.hits, 'login': user_login,'user_profile': dict['user_profile'],'quips': quips,
'users_followees': dict['users_followees'], 'users_followers': dict['users_followers'], 'displayname': dict['displayname'],
'followees_count':dict['followees_count'], 'followers_count':dict['followers_count'], 'is_receiver_following':dict['is_receiver_following'],
'quips_for': quips_for,'is_following': dict['is_following'],'is_following_on_im': dict['is_following_on_im'],
'logged_in_user_profile': dict['logged_in_user_profile'], 'profile_for_display': dict['profile_for_display'],'favs_count':dict['favs_count'],
'kwip_count':kwip_count(dict['user']),'comment_count':comment_count(dict['user']),
'revision_number': settings.REVISION_NUMBER,}, context_instance=template.RequestContext(request))
示例13: search
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def search(request):
from django.core.paginator import ObjectPaginator, InvalidPage
from django.db.models import Q
if not request.GET:
return render_to_response('search.html', {})
q = request.GET['q'].lower()
page = int(request.GET.get('page',1))
paginate_by = 10
message = '';
# keywords = q.split()
# sql = ""
# first = True
# for word in keywords:
# if first:
# sql += "(name LIKE '%%" + word + "%%' OR description LIKE '%%" + word + "%%')"
# first = False
# else:
# sql += " AND (name LIKE '%%" + word + "%%' OR description LIKE '%%" + word + "%%')"
sql = "MATCH (name,description) AGAINST (\"%s\")" % q
# paginator=ObjectPaginator(Article.objects.extra(where=[sql]).exclude(status='P').exclude(status='N'),paginate_by)
paginator=ObjectPaginator(Article.objects.extra(where=["MATCH (name,description) AGAINST (\"%s\")"], params=[q]).exclude(status='P').exclude(status='N'),paginate_by)
# results = Article.objects.search("%s" % q).exclude(status='P').exclude(status='N')[:5]
try:
results = paginator.get_page(page-1)
except (InvalidPage, ValueError):
results = []
message = 'No results'
return render_to_response('search.html', { 'results': results, 'q': q, 'message': message,
'is_paginated': paginator.pages > 1, 'results_per_page': paginate_by,
'has_next': paginator.has_next_page(page-1), 'has_previous':
paginator.has_previous_page(page-1), 'page': page, 'next': page + 1,
'previous': page - 1, 'pages': paginator.pages, 'hits' :
paginator.hits, } )
示例14: __init__
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def __init__(self, queryset, request=None, pageno=1, paginate_by=15, urlprefix='', urlnames=urlnames):
if isinstance(queryset, QuerySet):
self.queryset = queryset
else:
self.queryset = QuerysetWrapper(queryset)
self.paginate_by = paginate_by
self.request = request
self.urlprefix = urlprefix
self.urlname = urlnames
self.pageno = pageno
paginator = ObjectPaginator(self.queryset, paginate_by)
lastpage = math.ceil(1.0*self.queryset.count()/paginate_by)
if self.request:
page = self.request.GET.get('page', 1)
else:
page = self.pageno
try:
if isinstance(page, str):
if not page.isdigit():
page = 'last'
page = lastpage
page = int(page)
if page > lastpage:
page = lastpage
object_list = paginator.get_page(page - 1)
except (InvalidPage, ValueError):
object_list = []
self.is_paginated = paginator.pages > 1
self.results_per_page = paginate_by
self.has_next = paginator.has_next_page(page - 1)
self.has_previous = paginator.has_previous_page(page - 1)
self.page = page
self.next = page + 1
self.previous = page - 1
self.pages = paginator.pages
self.hits = paginator.hits
self.object_list = object_list
示例15: get
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import has_next_page [as 别名]
def get(self):
self.session = Session()
if CheckAuth(self) is False:
return DoAuth(self, '/writer/overview')
site_domain = Datum.get('site_domain')
site_domain_sync = Datum.get('site_domain_sync')
site_name = Datum.get('site_name')
site_author = Datum.get('site_author')
site_slogan = Datum.get('site_slogan')
site_analytics = Datum.get('site_analytics')
if site_domain is None:
site_domain = os.environ['HTTP_HOST']
Datum.set('site_domain', os.environ['HTTP_HOST'])
if site_domain_sync is None:
site_domain_sync = os.environ['HTTP_HOST']
Datum.set('site_domain_sync', os.environ['HTTP_HOST'])
articles = memcache.get('writer_articles')
if articles is None:
articles = Article.all().order('-created')
memcache.set('writer_articles', articles, 86400)
paginator = ObjectPaginator(articles, PAGE_SIZE)
try:
page = int(self.request.get('page', 0))
articles = paginator.get_page(page)
except InvalidPage:
articles = paginator.get_page(int(paginator.pages - 1))
if paginator.pages > 1:
is_paginated = True
else:
is_paginated = False
if site_domain is None or site_name is None or site_author is None:
site_configured = False
else:
site_configured = True
if is_paginated:
self.session['page'] = page
urls = memcache.get('writer_urls')
if urls is None:
everything = Article.all().order('-title_url')
urls = []
for article in everything:
urls.append(article.title_url)
memcache.set('writer_urls', urls, 86400)
template_values = {
'site_configured' : site_configured,
'is_paginated' : is_paginated,
'page_size' : PAGE_SIZE,
'page_has_next' : paginator.has_next_page(page),
'page_has_previous' : paginator.has_previous_page(page),
'page' : page,
'next' : page + 1,
'previous' : page - 1,
'pages' : paginator.pages,
'articles' : articles,
'articles_total' : len(articles),
'page_range' : range(0, paginator.pages),
'urls' : urls
}
if site_analytics is not None:
template_values['site_analytics'] = site_analytics
if site_domain_sync is None:
q = site_domain
else:
q = site_domain + ' OR ' + site_domain_sync
mentions_web = memcache.get('mentions_web')
if mentions_web is None:
try:
mentions_web = feedparser.parse('http://blogsearch.google.com/blogsearch_feeds?hl=en&q=' + urllib.quote('link:' + Datum.get('site_domain')) + '&ie=utf-8&num=10&output=atom')
memcache.add('mentions_web', mentions_web, 3600)
except:
mentions_web = None
if mentions_web is not None:
template_values['mentions_web'] = mentions_web.entries
# mentions_twitter = memcache.get('mentions_twitter')
# if mentions_twitter is None:
# try:
# result = urlfetch.fetch(TWITTER_API_ROOT + 'search.json?q=' + urllib.quote(q))
# if result.status_code == 200:
# mentions_twitter = simplejson.loads(result.content)
# memcache.add('mentions_twitter', mentions_twitter, 3600)
# except:
# mentions_twitter = None
# if mentions_twitter is not None:
# if len(mentions_twitter['results']) > 0:
# template_values['mentions_twitter'] = mentions_twitter['results']
template_values['system_version'] = VERSION
path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'overview.html')
self.response.out.write(template.render(path, template_values))