Commit b8706a96b3ca25f555e36ac793ccc6a842a12188
1 parent
d1e14f3f
Exists in
master
and in
5 other branches
Adding pagination [Issue #13]
Showing
4 changed files
with
35 additions
and
1 deletions
Show diff stats
@@ -0,0 +1,9 @@ | @@ -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 | \ No newline at end of file | 10 | \ No newline at end of file |
@@ -0,0 +1,22 @@ | @@ -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 | \ No newline at end of file | 23 | \ No newline at end of file |
users/templates/list_users.html
1 | {% extends 'base.html' %} | 1 | {% extends 'base.html' %} |
2 | 2 | ||
3 | -{% load i18n %} | 3 | +{% load i18n pagination %} |
4 | 4 | ||
5 | {% block breadcrumbs %} | 5 | {% block breadcrumbs %} |
6 | <div class="row"> | 6 | <div class="row"> |
@@ -50,5 +50,8 @@ | @@ -50,5 +50,8 @@ | ||
50 | </div> | 50 | </div> |
51 | </div> | 51 | </div> |
52 | {% endfor %} | 52 | {% endfor %} |
53 | + {% pagination request paginator page_obj %} | ||
54 | + {% else %} | ||
55 | + | ||
53 | {% endif %} | 56 | {% endif %} |
54 | {% endblock %} | 57 | {% endblock %} |