Skip to main content

Easy paging for the web.

Project description

web-paging

Easy paging for the web.

Description

web-paging is a simple library for paginating through web responses.

Getting started

Install via pip (ideally in a virtualenv):

pip install web-paging

Then use the web_paging.pageable decorator to wrap any pageable view functions. E.g. if using Flask:

from functools import partial

from flask import Flask, request, render_template
import web_paging


app = Flask(__name__)


def get_flask_arg(name, default):
    return request.args.get(name, default)


pageable = partial(
    web_paging.pageable,
    param_getter=lambda name, default: request.args.get(name, default),
    full_path_getter=lambda: request.full_path,
    response_factory=render_template
)


@app.get('/pageable')
@pageable('items.html')
def pageable_view(paging_key):
    items, next_paging_key = find_items(paging_key=paging_key)
    return dict(items=items), next_paging_key

The view is passed a paging key which can be used to identify the correct items to return. This is just a dict containing the attributes needed to find the correct results for the current page. For example, in a DynamoDB Query this dict would contain the attributes needed to create the ExclusiveStartKey. Similarly, the next_paging_key would be a dict created from the LastEvaluatedKey, containing the attributes needed to create the ExclusiveStartKey for the next page.

The response_factory function (flask.render_template in the example above) is passed the template name and a context object, containing the context returned from the view function (dict(items=items) in this example), plus some variables to render pagination links:

{% if web_paging_paging_tokens %}
<p>
  {% if web_paging_previous_path %}
    <a href="{{ web_paging_previous_path }}">
      Previous page
    </a>
  {% endif %}
  {% if web_paging_next_path %}
    <a href="{{ web_paging_next_path }}">
      Next page
    </a>
  {% endif %}
</p>
{% endif %}

web_paging_previous_path and web_paging_next_path are instances of markupsafe.Markup.

The context also includes a couple of variables representing the page numbers of the previous and next pages. These variables are web_paging_next_page and web_paging_previous_page.

Flask Support

web-paging has built-in support for Flask. Install with:

pip install web-paging[Flask]

Then you can use the web_paging.flask_pageable decorator:

from web_paging import flask_pageable

@app.get('/pageable')
@flask_pageable('items.html')
def pageable_view(paging_key):
    items, next_paging_key = find_items(paging_key=paging_key)
    return dict(items=items), next_paging_key

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

web_paging-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

web_paging-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file web_paging-0.2.0.tar.gz.

File metadata

  • Download URL: web_paging-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for web_paging-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a4f2a896163e86a7a85b1da3d10cb5d99ebcb2fd1fef4da2676b7e392e6ae47d
MD5 dc7abe97638c52fd6b89be5875dd769c
BLAKE2b-256 7aae8b891a3f4b7fad1e7a50b6c30217aae41a8bd236c715f7229645b0a59637

See more details on using hashes here.

Provenance

The following attestation bundles were made for web_paging-0.2.0.tar.gz:

Publisher: python-publish.yml on andycaine/web-paging

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file web_paging-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: web_paging-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for web_paging-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13a8156f7df2a478a22bf2bea6f3592fc4d15aca554d7cd11a1e31b8a1b1b8cd
MD5 f3fdad1f20526127c00800b4f7ba68f7
BLAKE2b-256 edfd60a84985822bf64923b0408ac69449e1cc61875d45b0f31a0f66462095ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for web_paging-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on andycaine/web-paging

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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