From d88c4632cd77f10258f92433384cd18ab92b7af1 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 12 Jan 2020 03:40:19 +0100 Subject: [PATCH] Add (simple) Bootstrap 4 paginator helper tag. --- .../base/templates/bootstrap_paginator.html | 49 +++++++++++++++++++ drakul/base/templatetags/base_extras.py | 8 +++ 2 files changed, 57 insertions(+) create mode 100644 drakul/base/templates/bootstrap_paginator.html diff --git a/drakul/base/templates/bootstrap_paginator.html b/drakul/base/templates/bootstrap_paginator.html new file mode 100644 index 0000000..0158998 --- /dev/null +++ b/drakul/base/templates/bootstrap_paginator.html @@ -0,0 +1,49 @@ +{% load base_extras %} + + +{% if is_paginated %} + +{% endif %} diff --git a/drakul/base/templatetags/base_extras.py b/drakul/base/templatetags/base_extras.py index d0b1dd3..d6276a1 100644 --- a/drakul/base/templatetags/base_extras.py +++ b/drakul/base/templatetags/base_extras.py @@ -8,3 +8,11 @@ def active(context, url_name): if context["request"].resolver_match.url_name == url_name: return "active" return "" + + +@register.simple_tag() +def paginator_pages(page_range: range, current_number: int, margin=5): + return range( + max(page_range.start, current_number - margin), + min(page_range.stop, current_number + margin + 1) + )