Skip to main content

Easy pagination for Pyramid applications

Project description

Easy pagination for Pyramid applications!

Project

TL;DR

Install with:

$ pip install pyramid_pagination

With pagination:

from pyramid_pagination import paginate

@paginate
def view(request): return range(30)

A request without parameters results in:

{
  "result": [0, 1, 2, ... , 22, 23, 24],
  "page": {
    "offset": 0,
    "limit": 25,
    "count": 30,
    "attribute": "result"
  }
}

Paginating with some defaults changed and adding some attribute-based sort methods:

from pyramid_pagination import paginate

@paginate(limit_default=2, comparers=['name', 'value'])
def view(request):
  return [
    dict(name='alph', value=1),
    dict(name='beta', value=2),
    dict(name='zeta', value=3),
    dict(name='alph', value=4),
  ]

A request with parameters ?page.offset=1&page.limit=3&page.sort=name-,value results in:

{
  "result": [
    {"name": "beta", "value": 2},
    {"name": "alph", "value": 1},
    {"name": "alph", "value": 4}
  ],
  "page": {
    "offset": 1,
    "limit": 3,
    "count": 4,
    "sort": "name-,value",
    "attribute": "result"
  }
}

Project details


Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page