Commit b8706a96b3ca25f555e36ac793ccc6a842a12188

Authored by Zambom
1 parent d1e14f3f

Adding pagination [Issue #13]

core/templates/pagination.html 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<nav aria-label="Page navigation">
  2 + <ul class="pagination">
  3 + {% for page_number in paginator.page_range %}
  4 + <li{% if page_obj.number == page_number %} class="active"{% endif %}>
  5 + <a href="?page={{ page_number }}{{ getvars }}">{{ page_number }}</a>
  6 + </li>
  7 + {% endfor %}
  8 + </ul>
  9 +</nav>
0 10 \ No newline at end of file
... ...
core/templatetags/__init__.py 0 → 100644
core/templatetags/pagination.py 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +from django import template
  2 +
  3 +register = template.Library()
  4 +
  5 +
  6 +@register.inclusion_tag('pagination.html')
  7 +def pagination(request, paginator, page_obj):
  8 + context = {
  9 + 'request': request,
  10 + 'paginator': paginator,
  11 + 'page_obj': page_obj,
  12 + }
  13 +
  14 + getvars = request.GET.copy()
  15 +
  16 + if 'page' in getvars:
  17 + del getvars['page']
  18 +
  19 + if len(getvars) > 0:
  20 + context['getvars'] = '&%s' % getvars.urlencode()
  21 +
  22 + return context
0 23 \ No newline at end of file
... ...
users/templates/list_users.html
1 1 {% extends 'base.html' %}
2 2  
3   -{% load i18n %}
  3 +{% load i18n pagination %}
4 4  
5 5 {% block breadcrumbs %}
6 6 <div class="row">
... ... @@ -50,5 +50,8 @@
50 50 </div>
51 51 </div>
52 52 {% endfor %}
  53 + {% pagination request paginator page_obj %}
  54 + {% else %}
  55 +
53 56 {% endif %}
54 57 {% endblock %}
... ...