diff --git a/gawa/blog/templates/blog/browse.html b/gawa/blog/templates/blog/browse.html index ad78f84..58a55b6 100644 --- a/gawa/blog/templates/blog/browse.html +++ b/gawa/blog/templates/blog/browse.html @@ -19,7 +19,7 @@
+ style="display: inline-block">

Browse

{# center headline on small screens #} @@ -40,25 +40,49 @@ aria-label="Search" placeholder="{% trans "Search" %}" required="" + {% if filters.search %}value="{{ filters.search }}"{% endif %} id="id_search">
- + +
+
+
+
+ +
+
+
+
+ +
+
- @@ -70,7 +94,7 @@ {# TODO: display some info if the queryset is empty #} {# TODO: pagination #} {% for post in posts %} -
+
0: + raw_keywords = self.request.GET["keywords"] + raw_keywords = raw_keywords.split('+') + keywords: list[Keyword] = [] + for raw_keyword in raw_keywords: + try: + keywords.append(Keyword.objects.get(slug=raw_keyword)) + except Keyword.DoesNotExist: + pass + logger.debug(f"found kws: {keywords}") + objects = objects.filter(keywords__in=keywords) return objects def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['featured_posts'] = BlogPost.objects.filter(featured=True) context['categories'] = Category.objects.all() + + context["filters"] = {} + if "category" in self.request.GET and len( + self.request.GET["category"].strip()) > 0: + category = self.request.GET["category"] + try: + category = Category.objects.get(slug=category) + context["filters"]["category"] = category + except Category.DoesNotExist: + context["filters"]["category"] = None + + if "search" in self.request.GET and len( + self.request.GET["search"].strip()) > 0: + search = self.request.GET["search"] + context["filters"]["search"] = search + + if "keywords" in self.request.GET and len( + self.request.GET["keywords"].strip()) > 0: + keywords = self.request.GET["keywords"] + keywords = keywords.split('+') + context["filters"]["keywords"] = keywords return context