From 324d3acfdf3cc024b2cc1edc721085448d36ccda Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 14 Nov 2022 06:53:18 -0500 Subject: adding context processors and removing unneeded js --- blog/context_processors.py | 8 ++++---- blog/views.py | 2 +- templates/blog/home.html | 7 ------- thatcomputerscientist/settings.py | 2 ++ 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/blog/context_processors.py b/blog/context_processors.py index de9371ae..4df11416 100644 --- a/blog/context_processors.py +++ b/blog/context_processors.py @@ -6,10 +6,10 @@ def recent_posts(): post.excerpt = post.body.split('>')[1].split('<')[0] return recent_posts -def categories(): +def categories(request): categories = Category.objects.all() - return categories + return {'categories': categories} -def archives(): +def archives(request): archives = Post.objects.filter(is_public=True).dates('date', 'month', order='DESC') - return archives + return {'archives': archives} diff --git a/blog/views.py b/blog/views.py index 9fa95801..b514750a 100644 --- a/blog/views.py +++ b/blog/views.py @@ -18,7 +18,7 @@ from announcements.models import Announcement def home(request): announcements = Announcement.objects.filter(is_public=True).order_by('-created_at') announcements = announcements if len(announcements) > 0 else None - return render(request, 'blog/home.html', {'title': 'Home', 'recent_posts': recent_posts(), 'categories': categories(), 'archives': archives(), 'announcements': announcements}) + return render(request, 'blog/home.html', {'title': 'Home', 'recent_posts': recent_posts(), 'announcements': announcements}) def account(request): user = request.user diff --git a/templates/blog/home.html b/templates/blog/home.html index 02897092..802ed7b8 100644 --- a/templates/blog/home.html +++ b/templates/blog/home.html @@ -84,16 +84,9 @@ reading...

-
{% endfor %} - {% endif %} {% endblock %} diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py index 8d95e329..b56f96f9 100644 --- a/thatcomputerscientist/settings.py +++ b/thatcomputerscientist/settings.py @@ -84,6 +84,8 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'blog.context_processors.categories', + 'blog.context_processors.archives', ], }, }, -- cgit v1.2.3