{% load paginator_tags %}

<ul class="pagination {% size size %}">

  {% if page_obj.has_previous %}
    <li class="page-item">
      <a class="page-link" href="?{% url_replace 'page' page_obj.previous_page_number %}">{% previous_name name=previous_name %}</a>
    </li>
  {% else %}
    <li class="page-item disabled">
      <a class="page-link" href="#">{% previous_name name=previous_name %}</a>
    </li>
  {% endif %}

  {% if page_obj.paginator.num_pages < elastic %}
    {% for page_num in page_obj.paginator.page_range %}
      <li class="page-item {% if page_obj.number == page_num %}active{% endif %}">
          <a class="page-link active" href="?{% url_replace 'page' page_num %}">{{ page_num }}</a>
      </li>
  {% endfor %}
  {% else %}

  {% for page_num in page_obj.paginator.page_range %}
    {% ellipsis_or_number page_obj.paginator page_num as answer %}
    {% if answer != None %}
      {% if answer == '...' %}
        <li class="page-item disabled">
            <a class="page-link" href="?{% url_replace 'page' page_num %}">{{ answer }}</a>
        </li>
      {% else %}
        <li class="page-item {% if page_obj.number == page_num %}active{% endif %}">
            <a class="page-link active" href="?{% url_replace 'page' page_num %}">{{ answer }}</a>
        </li>
      {% endif %}
    {% endif %}
  {% endfor %}

  {% endif %}
  {% if page_obj.has_next %}
      <li class="page-item">
        <a class="page-link" href="?{% url_replace 'page' page_obj.next_page_number %}">{% next_name name=next_name %}</a>
      </li>
  {% else %}
      <li class="page-item disabled">
        <a class="page-link" href="#">{% next_name name=next_name %}</a>
      </li>
  {% endif %}

</ul>
