Example Usage of Very basic CouchDB Paginator
An Example setup of CouchDB with django can be found at: Eric Florenzanos post about django+couchdb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | ### Example usage of SimpleCouchPaginator
from myproject.db.couchdb import db
from paginatoe import SimpleCouchPaginator, CouchPaginator
MIN_INT_DATE = 0
MAX_INT_DATE = 9999999999999
MIN_STRING = u''
MAX_STRING = u"\u9999"
def myview1(request):
item_type_viewname = 'mydesigndoc/by_user_date_type'
pages_item_type_viewname = 'mydesigndoc/pages-by_user_date_type'
username = request.user.username
pages_view = db.view(pages_item_type_viewname,
endkey=[username, MIN_INT_DATE, MIN_STRING],
startkey=[username, MAX_INT_DATE, MAX_STRING],
descending=True,
)
myitems = db.view(item_type_viewname,
include_docs=True,
endkey=[username, MIN_INT_DATE, MIN_STRING],
startkey=[username, MAX_INT_DATE, MAX_STRING],
descending=True,
)
try:
page_number = request.GET.get('page', 1)
paginate = CouchPaginator(myitems, count, pages_view=pages_view)
page = paginate.page(page_number)
items = paginate.object_list
except EmptyPage:
raise Http404("Page %s empty" % page_number)
except PageNotAnInteger:
raise Http404("No page '%s'" % page_number)
context = {
'items': items,
'paginate': paginate,
'page': page,
}
return render_to_response("test1.html", context,
context_instance=RequestContext(request)
)
def myview2(request, count=10):
item_type_viewname = 'mydesigndoc/by_user_date_type'
username = request.user.username
inquiry_items = db.view(item_type_viewname,
include_docs=True,
endkey=[username, MIN_INT_DATE, MIN_STRING],
startkey=[username, MAX_INT_DATE, MAX_STRING],
descending=True,
)
try:
page = request.GET.get('page', 1)
paginate = Paginator(count, inquiry_items)
paginate.page(page)
items = paginate.object_list
except EmptyPage:
raise Http404("Page %s empty" % page)
except PageNotAnInteger:
raise Http404("No page '%s'" % page)
context = {
'items': items,
'paginate': paginate,
}
return render_to_response("test2.html", context,
context_instance=RequestContext(request)
)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.