{% load i18n %}

{% if is_paginated %}
    <ul>
        {% if page_obj.has_previous %}
            <li>
                <a href="?page={{ page_obj.previous_page_number }}">
                    {% trans "Previous" %}
                </a>
            </li>
        {% endif %}

        {% if paginator.num_pages > pagination.pages_start %}
            {% if page_obj.number > pagination.pages_visible_total %}
                <li><a href="?page={{ page_obj.number|add:pagination.pages_visible_total_negative }}">...</a></li>
            {% endif %}

            {% for num in paginator.page_range %}
                {% if num == page_obj.number %}
                    <li class="active"><span>{{ num }}</span></li>
                {% elif num > page_obj.number|add:pagination.pages_visible_total_negative and num < page_obj.number|add:pagination.pages_visible_total %}
                    <li><a href="?page={{ num }}">{{ num }}</a></li>
                {% endif %}
            {% endfor %}

            {% if page_obj.number < paginator.num_pages|add:pagination.pages_visible_negative %}
                <li><a href="?page={{ page_obj.number|add:pagination.pages_visible_total }}">...</a></li>
            {% endif %}
        {% else %}
            {% for num in page_obj.paginator.page_range %}
                {% if num == page_obj.number %}
                    <li class="active"><span>{{ num }}</span></li>
                {% else %}
                    <li><a href="?page={{ num }}">{{ num }}</a></li>
                {% endif %}
            {% endfor %}
        {% endif %}

        {% if page_obj.has_next %}
            <li>
                <a href="?page={{ page_obj.next_page_number }}">
                    {% trans "Next" %}
                </a>
            </li>
        {% endif %}
    </ul>
{% endif %}
