========================================
Cursor and standard paginator for django
========================================
|codecov| |version| |downloads| |license|
This package is used to create standard or cursor navigation for django.
It has builtin templates, so you can use this library with minimal effort.
Library can be used with `jinja2` templates. If you are using ``django_jinja``
package, additional template tags are automatically registered to `jinja2`
engine.
If you are using cursor pagination, the queryset must be ordered with
combination of data fields, which are unique across query.
Cursor pagination supports checking for next / previous page presence without
any additional queries. There is used only single query to select records, no
additional queries to `count` checking or next / previous checking.
Install
-------
.. code:: bash
pip install django-universal-paginator
To ``INSTALLED_APPS`` add ``django_universal_paginator``.
.. code:: python
INSTALLED_APPS = (
# ...
'django_universal_paginator',
)
Settings
--------
Classical paginator support following settings:
``PAGINATOR_ON_EACH_SIDE``
Count of links around current page, default: 3
``PAGINATOR_ON_ENDS``
Link count on start / end of list, default: 1
``PAGINATOR_TEMPLATE_NAME``
Default template name for paginator, default: ``'paginator/paginator.html'``
Usage
-----
Template
^^^^^^^^
To use this library first add ``{% pagination %}`` to django template or
``{{ pagination() }}`` to jinja2 template.
.. code:: html
<!-- object_list.html -->
{% load paginator_tags %}
<ul>
{% for object in object_list %}
<li>{{ object }}</li>
{% endfor %}
</ul>
<div class="pagination">{% pagination %}</div>
To modify style look to
`paginator.html <https://github.com/mireq/django-universal-paginator/blob/master/django_universal_paginator/templates/paginator/paginator.html>`_.
URLs
^^^^
This package can be used without URL modification, but if you want clean URL
patterns without GET parameters, like ``/object-list/3/``, you can use following
code (example contains both methods - standard and cursor).
.. code:: python
# urls.py
from django.urls import path, register_converter
from django_universal_paginator.converter import PageConverter, CursorPageConverter
register_converter(PageConverter, 'page')
register_converter(CursorPageConverter, 'cursor_page')
# standard
url(r'^object-list/<page:page>', ObjectList.as_view(), name='object_list'),
# or cursor
url(r'^cursor/<cursor_page:page>', ObjectList.as_view(), name='cursor_list'),
Classical navigation
^^^^^^^^^^^^^^^^^^^^
To use classical navigation, just add ``paginate_by`` attribute to class based
list view.
.. code:: python
# views.py
class ObjectList(ListView):
paginate_by = 10
# model = ...
If you are using function based views, you can use
``django_universal_paginator.utils.paginate_queryset``.
.. code:: python
# views.py
from django_universal_paginator.utils import paginate_queryset
def list_view(request):
queryset = Book.objects.order_by('pk')
paginate_by = 10
page = 1
paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page,
paginate_by)
context = {
"paginator": paginator,
"page_obj": page,
"is_paginated": is_paginated,
"object_list": queryset,
}
reutrn render_to_string("list.html", context)
Cursor pagination
^^^^^^^^^^^^^^^^^
To use cursor pagination, queryset must be correctly ordered (order key must be
combination of keys which are unique across queryset).
.. code:: python
# views.py
from django.views.generic import ListView
from django_universal_paginator.cursor import CursorPaginateMixin
class List(CursorPaginateMixin, ListView):
paginate_by = 10
queryset = Book.objects.order_by('pk')
.. |codecov| image:: https://codecov.io/gh/mireq/django-universal-paginator/branch/master/graph/badge.svg?token=QGY5B5X0F3
:target: https://codecov.io/gh/mireq/django-universal-paginator
.. |version| image:: https://badge.fury.io/py/django-universal-paginator.svg
:target: https://pypi.python.org/pypi/django-universal-paginator/
.. |downloads| image:: https://img.shields.io/pypi/dw/django-universal-paginator.svg
:target: https://pypi.python.org/pypi/django-universal-paginator/
.. |license| image:: https://img.shields.io/pypi/l/django-universal-paginator.svg
:target: https://pypi.python.org/pypi/django-universal-paginator/
Raw data
{
"_id": null,
"home_page": "",
"name": "django-universal-paginator",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "pagination,cursor,simple,cursor pagination,simple pagination",
"author": "",
"author_email": "Miroslav Bend\u00edk <miroslav.bendik@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/40/78/1ab3790bcfa4bc7c8de1983e699f0deae156cd4e48e6ddeb81c6603cfa46/django_universal_paginator-1.4.0.tar.gz",
"platform": null,
"description": "========================================\nCursor and standard paginator for django\n========================================\n\n|codecov| |version| |downloads| |license|\n\nThis package is used to create standard or cursor navigation for django.\n\nIt has builtin templates, so you can use this library with minimal effort.\nLibrary can be used with `jinja2` templates. If you are using ``django_jinja``\npackage, additional template tags are automatically registered to `jinja2`\nengine.\n\nIf you are using cursor pagination, the queryset must be ordered with\ncombination of data fields, which are unique across query.\n\nCursor pagination supports checking for next / previous page presence without\nany additional queries. There is used only single query to select records, no\nadditional queries to `count` checking or next / previous checking.\n\nInstall\n-------\n\n.. code:: bash\n\n\tpip install django-universal-paginator\n\nTo ``INSTALLED_APPS`` add ``django_universal_paginator``.\n\n.. code:: python\n\n\tINSTALLED_APPS = (\n\t\t# ...\n\t\t'django_universal_paginator',\n\t)\n\nSettings\n--------\n\nClassical paginator support following settings:\n\n``PAGINATOR_ON_EACH_SIDE``\n\tCount of links around current page, default: 3\n``PAGINATOR_ON_ENDS``\n\tLink count on start / end of list, default: 1\n``PAGINATOR_TEMPLATE_NAME``\n\tDefault template name for paginator, default: ``'paginator/paginator.html'``\n\nUsage\n-----\n\nTemplate\n^^^^^^^^\n\nTo use this library first add ``{% pagination %}`` to django template or\n``{{ pagination() }}`` to jinja2 template.\n\n.. code:: html\n\n\t<!-- object_list.html -->\n\t{% load paginator_tags %}\n\n\t<ul>\n\t\t{% for object in object_list %}\n\t\t\t<li>{{ object }}</li>\n\t\t{% endfor %}\n\t</ul>\n\n\t<div class=\"pagination\">{% pagination %}</div>\n\nTo modify style look to\n`paginator.html <https://github.com/mireq/django-universal-paginator/blob/master/django_universal_paginator/templates/paginator/paginator.html>`_.\n\nURLs\n^^^^\n\nThis package can be used without URL modification, but if you want clean URL\npatterns without GET parameters, like ``/object-list/3/``, you can use following\ncode (example contains both methods - standard and cursor).\n\n.. code:: python\n\n\t# urls.py\n\n\tfrom django.urls import path, register_converter\n\tfrom django_universal_paginator.converter import PageConverter, CursorPageConverter\n\n\tregister_converter(PageConverter, 'page')\n\tregister_converter(CursorPageConverter, 'cursor_page')\n\n\t# standard\n\turl(r'^object-list/<page:page>', ObjectList.as_view(), name='object_list'),\n\t# or cursor\n\turl(r'^cursor/<cursor_page:page>', ObjectList.as_view(), name='cursor_list'),\n\n\nClassical navigation\n^^^^^^^^^^^^^^^^^^^^\n\nTo use classical navigation, just add ``paginate_by`` attribute to class based\nlist view.\n\n\n.. code:: python\n\n\t# views.py\n\n\tclass ObjectList(ListView):\n\t\tpaginate_by = 10\n\t\t# model = ...\n\nIf you are using function based views, you can use\n``django_universal_paginator.utils.paginate_queryset``.\n\n.. code:: python\n\n\t# views.py\n\tfrom django_universal_paginator.utils import paginate_queryset\n\n\tdef list_view(request):\n\t\tqueryset = Book.objects.order_by('pk')\n\t\tpaginate_by = 10\n\t\tpage = 1\n\t\tpaginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page,\n\t\tpaginate_by)\n\n\t\tcontext = {\n\t\t\t\"paginator\": paginator,\n\t\t\t\"page_obj\": page,\n\t\t\t\"is_paginated\": is_paginated,\n\t\t\t\"object_list\": queryset,\n\t\t}\n\n\t\treutrn render_to_string(\"list.html\", context)\n\n\nCursor pagination\n^^^^^^^^^^^^^^^^^\n\nTo use cursor pagination, queryset must be correctly ordered (order key must be\ncombination of keys which are unique across queryset).\n\n.. code:: python\n\n\t# views.py\n\tfrom django.views.generic import ListView\n\tfrom django_universal_paginator.cursor import CursorPaginateMixin\n\n\tclass List(CursorPaginateMixin, ListView):\n\t\tpaginate_by = 10\n\t\tqueryset = Book.objects.order_by('pk')\n\n\n.. |codecov| image:: https://codecov.io/gh/mireq/django-universal-paginator/branch/master/graph/badge.svg?token=QGY5B5X0F3\n\t:target: https://codecov.io/gh/mireq/django-universal-paginator\n\n.. |version| image:: https://badge.fury.io/py/django-universal-paginator.svg\n\t:target: https://pypi.python.org/pypi/django-universal-paginator/\n\n.. |downloads| image:: https://img.shields.io/pypi/dw/django-universal-paginator.svg\n\t:target: https://pypi.python.org/pypi/django-universal-paginator/\n\n.. |license| image:: https://img.shields.io/pypi/l/django-universal-paginator.svg\n\t:target: https://pypi.python.org/pypi/django-universal-paginator/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple pagination for django",
"version": "1.4.0",
"project_urls": {
"changelog": "https://github.com/mireq/django-universal-paginator/blob/master/CHANGELOG.md",
"documentation": "https://github.com/mireq/django-universal-paginator",
"homepage": "https://github.com/mireq/django-universal-paginator",
"repository": "https://github.com/mireq/django-universal-paginator"
},
"split_keywords": [
"pagination",
"cursor",
"simple",
"cursor pagination",
"simple pagination"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6503f37cceb710df8919587c00fa5a2ebf1e6851a001a057be16d5d224ca0aea",
"md5": "5d824f1f0fdd5329fd3e885815cbda88",
"sha256": "c1c37f518a16a903c7e23c7c29b685864961bb9a951f9cf7d29219da14232c3c"
},
"downloads": -1,
"filename": "django_universal_paginator-1.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5d824f1f0fdd5329fd3e885815cbda88",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 13388,
"upload_time": "2023-09-12T06:26:10",
"upload_time_iso_8601": "2023-09-12T06:26:10.444924Z",
"url": "https://files.pythonhosted.org/packages/65/03/f37cceb710df8919587c00fa5a2ebf1e6851a001a057be16d5d224ca0aea/django_universal_paginator-1.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "40781ab3790bcfa4bc7c8de1983e699f0deae156cd4e48e6ddeb81c6603cfa46",
"md5": "9f9fcbd3e8794af6c0f011dd6d6f0f66",
"sha256": "7f29974c2ff104bd7b86dfb12e6222893834249d0878fe9febf5a6ad01cada49"
},
"downloads": -1,
"filename": "django_universal_paginator-1.4.0.tar.gz",
"has_sig": false,
"md5_digest": "9f9fcbd3e8794af6c0f011dd6d6f0f66",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 31184,
"upload_time": "2023-09-12T06:26:12",
"upload_time_iso_8601": "2023-09-12T06:26:12.553762Z",
"url": "https://files.pythonhosted.org/packages/40/78/1ab3790bcfa4bc7c8de1983e699f0deae156cd4e48e6ddeb81c6603cfa46/django_universal_paginator-1.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-12 06:26:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mireq",
"github_project": "django-universal-paginator",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "django-universal-paginator"
}