Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mardix/paginator.py

Paginator for SQLAlchemy query object, list or iterable
https://github.com/mardix/paginator.py

Last synced: 4 days ago
JSON representation

Paginator for SQLAlchemy query object, list or iterable

Awesome Lists containing this project

README

        

# Paginator

Paginator for SQLAlchemy query object, list or iterable

---

## Install

pip install paginator

### Simple Usage with an iterable

from paginator import Paginator

items = range(1, 1000)

items = Paginator(items, page=1, per_page=10)

for item in items:
pass

### Simple Usage with an iterable and callback

from paginator import Paginator

items = range(1, 1000)

def my_callback(item):
# do something
return item

items = Paginator(items, page=1, per_page=10, callback=my_callback)

for item in items:
pass

#### API

**Paginator(query, page=1, per_page=10, total=None, padding=0, callback=None, static_query=False)**

:param query: Iterable to paginate. Can be a query object, list or any iterables
:param page: current page
:param per_page: max number of items per page
:param total: Max number of items. If not provided, it will use the query to count
:param padding: Number of elements of the next page to show
:param callback: a function to callback on each item being iterated.
:param static_query: bool - When True it will return the query as is, without slicing/limit. Usally when using the paginator to just create the pagination.
:return:

### Jinja macro


{#: PAGINATION -------------------------------------------------------------- #}
{#
:paginator: iterator
:endpoint:
:prev: Text for previous button
:next: Text for Next button
:class_: A class name for pagination if customed. If you are extending the class
best to add the original class and your custom class
ie: 'pagination my_custom_pagination' or 'pager my_custom_page'
:pager: If true it will show a pager instead of numbered pagination

#}
{% macro pagination(paginator, endpoint=None, prev="", next="", class_=None, pager=False) %}
{% if not endpoint %}
{% set endpoint = request.endpoint %}
{% endif %}
{% if "page" in kwargs %}
{% set _ = kwargs.pop("page") %}
{% endif %}

{% if not class_ %}
{% set class_ = "pagination" %}
{% if pager %}
{% set class_ = "pager" %}
{% endif %}
{% endif %}

{% set _prev_btn = " %s" % prev %}
{% set _next_btn = " %s" % next %}





{% endmacro %}

### DOCUMENTATION IN CONSTRUCTION

---

(c) 2015 Mardix