Metadata-Version: 2.1
Name: py-paginator
Version: 1.0.1
Summary: Paginator to generate page numbers for pagination
Home-page: https://github.com/sujeetkv/py-paginator
Author: Sujeet Kumar
Author-email: sujeetkv90@gmail.com
License: MIT
Description: # py-paginator
        Paginator to generate page numbers for pagination
        
        [![Build Status](https://travis-ci.org/sujeetkv/py-paginator.svg?branch=master)](https://travis-ci.org/sujeetkv/py-paginator)
        
        ## Usage Example
        
        ```python
        from py_paginator import Paginator
        
        total_records = 400 # records count from database
        page = 1 # page number from url
        
        paginator = Paginator(total_items=total_records, item_limit=20, curr_page=page)
        ```
        
        use this `paginator` object in templates to create pagination links
        
        `paginator.item_limit` and `paginator.item_offset` can be used in database query to apply limit
        
        
        ## Sample jinja macro for flask framework
        
        ```html
        {#: PAGINATION ------------------------------------------------------ #}
        {#
            :paginator: paginator object
            :endpoint: flask request endpoint
            :only_pager: If True it will show a pager instead of numbered pagination
        #}
        {% macro pagination(paginator, endpoint=request.endpoint, only_pager=False) %}
            {% set __ = kwargs.update(request.args) %}
            {% if 'page' in kwargs %}
                {% set __ = kwargs.pop('page') %}
            {% endif %}
            {% if paginator.has_pages %}
            <nav aria-label="Page navigation">
                {% if only_pager %}
                    {% set pager = paginator.get_pager() %}
                    <ul class="pager">
                        <li class="previous{% if not paginator.has_prev %} disabled{% endif %}">
                            <a href="{% if paginator.has_prev %}{{ url_for(endpoint, page=pager.prev, **kwargs) }}{% else %}#{% endif %}"><span aria-hidden="true">&laquo;</span> Prev</a>
                        </li>
                        <li class="next{% if not paginator.has_next %} disabled{% endif %}">
                            <a href="{% if paginator.has_next %}{{ url_for(endpoint, page=pager.next, **kwargs) }}{% else %}#{% endif %}">Next <span aria-hidden="true">&raquo;</span></a>
                        </li>
                    </ul>
                {% else %}
                    <ul class="pagination">
                        {% for page_type, page_num in paginator.get_pages() %}
                            {% if page_type == 'prev' %}
                                {% if page_num %}
                                    <li><a href="{{ url_for(endpoint, page=page_num, **kwargs) }}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
                                {% else %}
                                    <li class="disabled"><span><span aria-hidden="true">&laquo;</span></span></li>
                                {% endif %}
                            {% elif page_type == 'next' %}
                                {% if page_num %}
                                    <li><a href="{{ url_for(endpoint, page=page_num, **kwargs) }}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
                                {% else %}
                                    <li class="disabled"><span><span aria-hidden="true">&raquo;</span></span></li>
                                {% endif %}
                            {% elif page_type == 'ellip' %}
                                <li class="disabled"><span><span aria-hidden="true">&hellip;</span></span></li>
                            {% elif page_type == 'curr' %}
                                <li class="active"><span>{{ page_num }}</span></li>
                            {% else %}
                                <li><a href="{{ url_for(endpoint, page=page_num, **kwargs) }}">{{ page_num }}</a></li>
                            {% endif %}
                        {% endfor %}
                    </ul>
                {% endif %}
            </nav>
            {% endif %}
        {% endmacro %}
        ```
        
Keywords: paginator py_paginator py-paginator
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Page Counters
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=2.7
Description-Content-Type: text/markdown
