5 messages in com.googlegroups.google-appengine[google-appengine] Re: Pagination sni...| From | Sent On | Attachments |
|---|---|---|
| mar...@google.com | 09 Apr 2008 11:23 | |
| Mike Axiak | 09 Apr 2008 11:28 | |
| Jared | 20 Apr 2008 23:57 | |
| Venkatesh Rangarajan | 22 Apr 2008 08:19 | |
| Jared | 23 May 2008 13:21 |
| Subject: | [google-appengine] Re: Pagination snippets![]() |
|---|---|
| From: | Jared (gree...@gmail.com) |
| Date: | 05/23/2008 01:21:25 PM |
| List: | com.googlegroups.google-appengine |
Finally got to playing around with this. Just something to point out...
Rather than displaying a 404 page when the page= number is set out of bounds, you could do something like this...
try: page = int(self.request.get('page',0)) visits = paginator.get_page(page) except: visits = paginator.get_page(int(paginator.pages-1))
Then, no matter how far off the deep end page is set to (20000 or something), the user will just get the last page. I kind of like that better than a 404 page, but that's personal preference.
On Apr 22, 11:19 am, "Venkatesh Rangarajan" <venk...@gmail.com> wrote:
Jared,
here is a working example. Let me know if it works for you.
My Handler (from django.core.paginator import ObjectPaginator, InvalidPage)
---------------------------------------- class ListAll(webapp.RequestHandler): def get(self): #visitors=db.GqlQuery("SELECT * FROM Visit") visitors=Visit.all() visitors.order('-date') visitors=visitors.fetch(limit=100) paginate_by =10 paginator = ObjectPaginator(visitors, paginate_by) #self.response.out.write(paginator.pages) try: page = int(self.request.get('page', 0)) visits = paginator.get_page(page) except InvalidPage: raise http.Http404 template_values = { 'visits': visits, 'is_paginated' : True, '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, 'action':action, } path = os.path.join(os.path.dirname(__file__), 'show.html') self.response.out.write(template.render(path, template_values))
----------------------------------------
Here is my Template HTML
---------------------------------------------------- {% if has_previous %} <a href="?q=ip&page={{ previous }}"> < < previous {{ page }} {% endif %} {% if has_next %} <a href="?q=ip&page={{ next }}"> next >> {% endif %} </tr></td> {% endifequal %}
------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to goog...@googlegroups.com
To unsubscribe from this group, send email to
goog...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---




