Well, I'm using this recipe(1) because cursor it's only a bookmark for
datastore. If I want prev,next feature you will need something more
than a cursor. (storing it in memcache? or things like that). You can
build something like Twitter, with his button "More tweets" or
something like that and to build a system which send new topics in the
forums to the subscribers. Both with cursors.

An example with cursors could be:

bookmark = self.request.get('bookmark', None)

query = Model.all().filter('example', 'prop').order('-other_prop')
if bookmark:
  query.with_cursor(bookmark)
query.fetch(30)
next = query.cursor()

self.response.out.write('print here the list')
self.response.out.write('<a href="page?bookmark=%s">link</a>' % next)

1. -http://appengine-cookbook.appspot.com/recipe/efficient-paging-for-
any-query-and-any-model/


On 6 feb, 02:23, Zeynel <[email protected]> wrote:
> I asked the question at StackOverflow and there was a good answer but
> I still could not make it 
> work:http://stackoverflow.com/questions/4840731/how-to-use-cursor-for-pagi...
>
> Nick Johnson has a blog post about it but it is more about the source
> code than a practical 
> example:http://blog.notdot.net/2010/02/New-features-in-1-3-1-prerelease-Cursors.
>
> Can anyone explain to me how cursor works for pagination? Thanks!
>
> This is the code I am using:
>
>             items = db.GqlQuery("SELECT * FROM Item ORDER BY date DESC
> LIMIT 30")
> #===========adding cursor here===========#
>             cursor = self.request.get("cursor")
>             if cursor: query.with_cursor(cursor)
>             items = query.fetch(30)
>             cursor  = query.cursor()
>
> #===========adding cursor here===========#
>
> #===========regular output===========#
>             self.response.out.write("<ol>")
>             for item in items:
>                 self.response.out.write("""<li>
>                 <a href="/vote/%s?type=%s"> ^ </a><a href="%s"><span
> id="large">%s</span></a>
>                 <span id='Small'>(%s)</span>
>                 <br />
>                 %s<br /> <span id='Small'>
>                 %s points %s by %s <a href="/item/%s"></a> |
>                 <a href="/item/%s#disqus_thread"></a>
>                 </span>
>                 </li><br /> """ %
>                 (str(item.key().id()), merchandise_type, item.url,
> item.title, urlparse(item.url).netloc,
>                 item.summary, item.points, item.date.strftime("%B %d,
> %Y %I:%M%p"),
>                 item.user_who_liked_this_item, str(item.key().id()),
> str(item.key().id())))
>
>             self.response.out.write("</ol>")
> #===========regular output===========#
>
> #===========link to cursor===========#
>             self.response.out.write("""<a href="/dir?type=%s?cursor=
> %s">Next Page</a>""" % (merchandise_type, cursor))

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to