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 a context variable 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file web_paging-0.3.0.tar.gz.
File metadata
- Download URL: web_paging-0.3.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f236f9c1092308be4671532f3377121d310d4bbd8831408eb5788c1771a829a8
|
|
| MD5 |
59297583dd6253e5c6d08c4ada92e5d8
|
|
| BLAKE2b-256 |
074b1e01851742d46fe2fd0c60628aeae4d4283dc847a4433f5d365749986cc0
|
Provenance
The following attestation bundles were made for web_paging-0.3.0.tar.gz:
Publisher:
python-publish.yml on andycaine/web-paging
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
web_paging-0.3.0.tar.gz -
Subject digest:
f236f9c1092308be4671532f3377121d310d4bbd8831408eb5788c1771a829a8 - Sigstore transparency entry: 179848562
- Sigstore integration time:
-
Permalink:
andycaine/web-paging@d526fb30cd33adf0f664c0f3fae69646dd35f9c7 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/andycaine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d526fb30cd33adf0f664c0f3fae69646dd35f9c7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file web_paging-0.3.0-py3-none-any.whl.
File metadata
- Download URL: web_paging-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6b993094d90614debae6de12453500e333514285b3394f9fadb868ee2090509
|
|
| MD5 |
f50b998bbbbc0ff925731eb11c89280b
|
|
| BLAKE2b-256 |
2a47a105a20ee0275e1243bf9fc50233e46e62f9bfd5e21f41db789e7b74f6ce
|
Provenance
The following attestation bundles were made for web_paging-0.3.0-py3-none-any.whl:
Publisher:
python-publish.yml on andycaine/web-paging
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
web_paging-0.3.0-py3-none-any.whl -
Subject digest:
f6b993094d90614debae6de12453500e333514285b3394f9fadb868ee2090509 - Sigstore transparency entry: 179848567
- Sigstore integration time:
-
Permalink:
andycaine/web-paging@d526fb30cd33adf0f664c0f3fae69646dd35f9c7 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/andycaine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d526fb30cd33adf0f664c0f3fae69646dd35f9c7 -
Trigger Event:
push
-
Statement type: