Login

Example usage of SimpleCouchPaginator

Author:
toke
Posted:
November 20, 2008
Language:
Python
Version:
1.0
Tags:
pagination paginator couchdb example
Score:
0 (after 0 ratings)

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

  1. Basic CouchDB Paginator (Updated) by toke 6 years, 3 months ago
  2. Convert a Couchdb document into a Python object by davej 6 years, 3 months ago
  3. Django-pagination with Bootstrap CSS by ronbeltran 2 years, 10 months ago
  4. django-pagination with "clean url" by pafa 3 years, 5 months ago
  5. BetterPaginator Template Code by spankalee 7 years, 10 months ago

Comments

Please login first before commenting.