blog-browse #40

Merged
PlexSheep merged 17 commits from blog-browse into devel 2023-10-08 14:46:09 +02:00
2 changed files with 24 additions and 5 deletions
Showing only changes of commit 06e3172234 - Show all commits

View File

@ -16,9 +16,15 @@
{% block main %}
<div class="container-fluid">
<div class="row mb-5">
<div class="col col-xxl mb-5">
{# TODO: center in mobile view #}
<div class="col col-xxl mb-5" id="headline">
<h1 class="display-1">Browse</h1>
{# center headline on small screens #}
<script>
if (screen.width < 480) {
col = document.getElementById("headline")
col.classList.add("text-center")
};
</script>
</div>
<div class="col-sm-3">
<div class="container-fluid w-100 h-100 p-2">

View File

@ -8,6 +8,7 @@ from start.views import SearchableView
import logging
logger = logging.getLogger(__name__)
class Index(TemplateView, SearchableView):
"""
The index page of the gawa/blog app.
@ -20,9 +21,11 @@ class Index(TemplateView, SearchableView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['featured_posts'] = BlogPost.objects.filter(featured=True, public=True)
context['featured_posts'] = BlogPost.objects.filter(
featured=True, public=True)
return context
class Post(DetailView):
"""
Main page of a blog post
@ -37,6 +40,7 @@ class Post(DetailView):
context['featured_posts'] = BlogPost.objects.filter(featured=True)
return context
class Browse(ListView):
"""
Scroll through a list of blog posts
@ -49,6 +53,15 @@ class Browse(ListView):
template_name = "blog/browse.html"
context_object_name = "posts"
def get_queryset(self):
objects = BlogPost.objects.all()
if "category" in self.request.GET and len(
self.request.GET["category"].strip()) > 0:
category = self.request.GET["category"]
category = Category.objects.get(slug=category)
objects = objects.filter(category=category)
return objects
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['featured_posts'] = BlogPost.objects.filter(featured=True)