diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 424b18f..017f293 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,12 @@ { "recommendations": [ - "charliermarsh.ruff" + "charliermarsh.ruff", + "akamud.vscode-theme-onedark", + "oven.bun-vscode", + "mhutchie.git-graph", + "github.vscode-pull-request-github", + "ms-python.python", + "robbowen.synthwave-vscode", + "bradlc.vscode-tailwindcss" ] } \ No newline at end of file diff --git a/package.json b/package.json index 5176889..5638f12 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "scripts": { "tailwindcss:build": "tailwindcss build -i src/brazil_blog/static/css/brazil_blog.css -o src/brazil_blog/static/css/brazil_blog_compiled.css", "tailwindcss:watch": "tailwindcss build -i src/brazil_blog/static/css/brazil_blog.css -o src/brazil_blog/static/css/brazil_blog_compiled.css --watch", - "tailwindcss:dev": "bun run tailwindcss:build && bun run tailwindcss:watch" + "tailwindcss:dev": "bun run tailwindcss:watch" }, "type": "module", "dependencies": { "cypress": "^13.10.0" } diff --git a/src/blog/models.py b/src/blog/models.py index cfc8f13..09348e8 100644 --- a/src/blog/models.py +++ b/src/blog/models.py @@ -23,18 +23,18 @@ def get_context(self, request): context = super().get_context(request) now = timezone.now() blogpages = ( - self.get_children() - .live() - .filter(blogpage__date__lte=now) - .order_by('-blogpage__date') - .specific() + BlogPage.objects + .child_of(self) + .live() + .filter(date__lte=now) + .order_by('-date') ) context['blogpages'] = blogpages # Author filter author_username = request.GET.get('author') if author_username: - blogpages = blogpages.filter(Q(blogpage__author__username=author_username)) + blogpages = blogpages.filter(Q(author__username=author_username)) # Date filter date_from = request.GET.get('date_from') @@ -43,17 +43,23 @@ def get_context(self, request): if date_from: date_from = parse_date(date_from) if date_from: - blogpages = blogpages.filter(blogpage__date__gte=date_from) + blogpages = blogpages.filter(date__gte=date_from) if date_to: date_to = parse_date(date_to) if date_to: - blogpages = blogpages.filter(blogpage__date__lte=date_to) + blogpages = blogpages.filter(date__lte=date_to) + + query = request.GET.get('query') + if query: + blogpages = blogpages.search(query, fields=['title', 'body']) context['blogpages'] = blogpages context['authors'] = User.objects.filter(blog_posts__isnull=False).distinct() context['page'] = self # Add this line for the reset button + context['active_filters'] = any([author_username, query, date_from, date_to]) + return context content_panels = Page.content_panels + [ @@ -86,8 +92,11 @@ class BlogPage(Page): body = RichTextField(blank=True) search_fields = Page.search_fields + [ + index.SearchField('title'), index.SearchField('intro'), index.SearchField('body'), + index.FilterField('username'), + index.FilterField('date'), ] content_panels = Page.content_panels + [ diff --git a/src/blog/templates/blog/includes/filter-bar.html b/src/blog/templates/blog/includes/filter-bar.html index 8d07049..742bc19 100644 --- a/src/blog/templates/blog/includes/filter-bar.html +++ b/src/blog/templates/blog/includes/filter-bar.html @@ -1,41 +1,134 @@ {% load wagtailcore_tags wagtailimages_tags user_tags %} -