Name | web-paging JSON |
Version |
0.2.1
JSON |
| download |
home_page | None |
Summary | Easy paging for the web. |
upload_time | 2024-11-30 14:15:35 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | MIT License |
keywords |
paging
flask
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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):
```bash
pip install web-paging
```
Then use the `web_paging.pageable` decorator to wrap any pageable view functions. E.g. if using Flask:
```python
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:
```html
{% 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:
```bash
pip install "web-paging[flask]"
```
Then you can use the `web_paging.flask_pageable` decorator:
```python
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
```
Raw data
{
"_id": null,
"home_page": null,
"name": "web-paging",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "paging, Flask",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/3c/97/6e1e6d01465449da240dcb5e57c04bec0246a5fcfcd45c58fa1d05884ef2/web_paging-0.2.1.tar.gz",
"platform": null,
"description": "# web-paging\n\nEasy paging for the web.\n\n## Description\n\n`web-paging` is a simple library for paginating through web responses.\n\n## Getting started\n\nInstall via pip (ideally in a virtualenv):\n\n```bash\npip install web-paging\n```\n\nThen use the `web_paging.pageable` decorator to wrap any pageable view functions. E.g. if using Flask:\n\n```python\nfrom functools import partial\n\nfrom flask import Flask, request, render_template\nimport web_paging\n\n\napp = Flask(__name__)\n\n\ndef get_flask_arg(name, default):\n return request.args.get(name, default)\n\n\npageable = partial(\n web_paging.pageable,\n param_getter=lambda name, default: request.args.get(name, default),\n full_path_getter=lambda: request.full_path,\n response_factory=render_template\n)\n\n\n@app.get('/pageable')\n@pageable('items.html')\ndef pageable_view(paging_key):\n items, next_paging_key = find_items(paging_key=paging_key)\n return dict(items=items), next_paging_key\n```\n\nThe 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.\n\nThe `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:\n\n```html\n{% if web_paging_paging_tokens %}\n<p>\n {% if web_paging_previous_path %}\n <a href=\"{{ web_paging_previous_path }}\">\n Previous page\n </a>\n {% endif %}\n {% if web_paging_next_path %}\n <a href=\"{{ web_paging_next_path }}\">\n Next page\n </a>\n {% endif %}\n</p>\n{% endif %}\n```\n\n`web_paging_previous_path` and `web_paging_next_path` are instances of `markupsafe.Markup`.\n\nThe 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`.\n\n## Flask Support\n\n`web-paging` has built-in support for Flask. Install with:\n\n```bash\npip install \"web-paging[flask]\"\n```\n\nThen you can use the `web_paging.flask_pageable` decorator:\n\n```python\nfrom web_paging import flask_pageable\n\n@app.get('/pageable')\n@flask_pageable('items.html')\ndef pageable_view(paging_key):\n items, next_paging_key = find_items(paging_key=paging_key)\n return dict(items=items), next_paging_key\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Easy paging for the web.",
"version": "0.2.1",
"project_urls": {
"Documentation": "https://github.com/andycaine/web-paging?tab=readme-ov-file#asaa",
"Homepage": "https://github.com/andycaine/web-paging",
"Repository": "https://github.com/andycaine/web-paging.git"
},
"split_keywords": [
"paging",
" flask"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "28f0c368ba8acf34326adf4025564ae2a422234e3e1da6eb99798e7afa7ebc48",
"md5": "9ca62b81f85e0071960243323bb32ed1",
"sha256": "81072f5dd182bac55fd607176359b327573bc6cd9ede2470c41dc8c46d275fff"
},
"downloads": -1,
"filename": "web_paging-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9ca62b81f85e0071960243323bb32ed1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5063,
"upload_time": "2024-11-30T14:15:25",
"upload_time_iso_8601": "2024-11-30T14:15:25.964094Z",
"url": "https://files.pythonhosted.org/packages/28/f0/c368ba8acf34326adf4025564ae2a422234e3e1da6eb99798e7afa7ebc48/web_paging-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3c976e1e6d01465449da240dcb5e57c04bec0246a5fcfcd45c58fa1d05884ef2",
"md5": "0bc0cf47dd3884fa3c77ed2654d240c0",
"sha256": "f988e7ad45ad7c3f57704416bb6004407e1612dfa3d2e681354f068938cbe359"
},
"downloads": -1,
"filename": "web_paging-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "0bc0cf47dd3884fa3c77ed2654d240c0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5172,
"upload_time": "2024-11-30T14:15:35",
"upload_time_iso_8601": "2024-11-30T14:15:35.391130Z",
"url": "https://files.pythonhosted.org/packages/3c/97/6e1e6d01465449da240dcb5e57c04bec0246a5fcfcd45c58fa1d05884ef2/web_paging-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-30 14:15:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "andycaine",
"github_project": "web-paging?tab=readme-ov-file#asaa",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "web-paging"
}