<!-- 
You can change the length to however long you want.
For the best result, use an odd number
 -->
{% set length = 5 %}

<!-- Don't edit the variables below -->
{% if form is defined %}
    {% if vulns is defined %}
        {% set listLength = vulns|length %}
    {% elif fixes is defined %}
        {% set listLength = fixes|length %}
    {% elif hosts is defined %}
        {% set listLength = hosts|length %}
    {% endif %}
    {% set r = form.r|int %}{% set pageLength = form.pageLength|int %}
{% endif %}

{% set page = (r/40)|int %}
{% set middle = (length/2)|int+1 %}
{% if page < middle %}
  {% set pre = page %}
  {% set post = length-page%}
{% else %}
  {% set pre = middle-1 %}
  {% set post = middle%}
{% endif %}

<div class="pagerdiv">
  <nav>
    <ul class="pagination">
     
      {% for n in range(pre,0,-1) %}
        <li><a href="javascript:previous({{r - n * pageLength}})">{{page - n+1}}</a></li>
      {% endfor %}
      <li class="active">
        <span>{{page+1}} <span class="sr-only">(current)</span></span>
      </li>
      
      {% for n in range(1,post) %}
        <li {% if listLength is defined and listLength < pageLength %}class="disabled"{% endif %}><a href="javascript:next({{r + n * pageLength}})">{{page + n+1}}</a></li>
      {% endfor %}
   
    </ul>
  </nav>
</div>
