From 247fe8e206003efb67c45fc14f1a20e0ef7e1a3e Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 8 Oct 2023 14:11:48 +0200 Subject: [PATCH] pagination works not compatible with search? --- gawa/blog/templates/blog/browse.html | 26 ++++++++++++++++++++++++++ gawa/blog/views.py | 1 + gawa/start/templatetags/helper_tags.py | 10 ++++++++++ 3 files changed, 37 insertions(+) diff --git a/gawa/blog/templates/blog/browse.html b/gawa/blog/templates/blog/browse.html index 8f84dc7..02b1c18 100644 --- a/gawa/blog/templates/blog/browse.html +++ b/gawa/blog/templates/blog/browse.html @@ -174,6 +174,32 @@ {% endfor %} + {% endif %} diff --git a/gawa/blog/views.py b/gawa/blog/views.py index 7ce7081..26a7ce1 100644 --- a/gawa/blog/views.py +++ b/gawa/blog/views.py @@ -57,6 +57,7 @@ class Browse(ListView): model = BlogPost template_name = "blog/browse.html" context_object_name = "posts" + paginate_by = 20 allow_empty = False # but we have a special get method def get_queryset(self): diff --git a/gawa/start/templatetags/helper_tags.py b/gawa/start/templatetags/helper_tags.py index e57a3bc..c580f82 100644 --- a/gawa/start/templatetags/helper_tags.py +++ b/gawa/start/templatetags/helper_tags.py @@ -13,3 +13,13 @@ register = Library() @register.simple_tag def format_time(timestamp: datetime, format: str = "%F %H:%M:%S %Z") -> str: return timestamp.strftime(format) + +@register.simple_tag(takes_context=True) +def query_transform(context, **kwargs): + """ + Modify the GET parameters of a request from templates + """ + query = context['request'].GET.copy() + for k, v in kwargs.items(): + query[k] = v + return query.urlencode()