browse url and template

This commit is contained in:
Christoph J. Scherr 2023-10-02 18:55:23 +02:00
parent c0750fdb30
commit 48a0d26745
4 changed files with 22 additions and 24 deletions

View File

@ -0,0 +1,17 @@
{% extends 'base.html' %}
{% load i18n %}
{% load helper_tags %}
{% get_current_language as LANGUAGE_CODE %}
{% block languagecode %}
{{ LANGUAGE_CODE }}
{% endblock languagecode %}
{% block title %}
{% translate "cscherr.de" %} - {% translate "Blog" %}
{% endblock title %}
{% block nav %}
{% include 'nav.html' %}
{% endblock nav %}
{% block main %}
<div class="container-xl">{{ category }}</div>
{% include 'blog/featured.html' %}
{% endblock main %}

View File

@ -5,7 +5,6 @@ from . import views
app_name: str = "blog" app_name: str = "blog"
urlpatterns = [ urlpatterns = [
path("", views.Index.as_view(), name="index"), path("", views.Index.as_view(), name="index"),
path("categories", views.CategoryList.as_view(), name="category_list"), path("browse", views.Browse.as_view(), name="browse"),
path("<slug:slug>", views.ArticleList.as_view(), name="article_list"),
path("<slug:category>/<slug:slug>", views.Post.as_view(), name="post"), path("<slug:category>/<slug:slug>", views.Post.as_view(), name="post"),
] ]

View File

@ -12,7 +12,7 @@ class Index(TemplateView, SearchableView):
""" """
The index page of the gawa/blog app. The index page of the gawa/blog app.
Utilizes a generic view, because I will do so for all views, Utilizes a generic view, because I will do so for all views,
a regular view function would suffice. a regular view function would suffice.
""" """
@ -21,7 +21,6 @@ class Index(TemplateView, SearchableView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**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)
logger.debug(f"loaded featured posts: {context['featured_posts']}")
return context return context
class Post(DetailView): class Post(DetailView):
@ -36,25 +35,9 @@ class Post(DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['featured_posts'] = BlogPost.objects.filter(featured=True) context['featured_posts'] = BlogPost.objects.filter(featured=True)
logger.debug(f"loaded featured posts: {context['featured_posts']}")
return context return context
class CategoryList(ListView): class Browse(ListView):
"""
Scroll through a list of blog Categories
"""
model=Category
template_name = "blog/categories.html"
context_object_name = "categories"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['featured_posts'] = BlogPost.objects.filter(featured=True)
logger.debug(f"loaded featured posts: {context['featured_posts']}")
return context
class ArticleList(ListView):
""" """
Scroll through a list of blog posts Scroll through a list of blog posts
@ -63,11 +46,10 @@ class ArticleList(ListView):
""" """
model=BlogPost model=BlogPost
template_name = "blog/posts.html" template_name = "blog/browse.html"
context_object_name = "posts" context_object_name = "posts"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['featured_posts'] = BlogPost.objects.filter(featured=True) context['featured_posts'] = BlogPost.objects.filter(featured=True)
logger.debug(f"loaded featured posts: {context['featured_posts']}")
return context return context

View File

@ -29,7 +29,7 @@
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="{% url 'blog:index' %}">{% translate "Start" %}</a></li> <li><a class="dropdown-item" href="{% url 'blog:index' %}">{% translate "Start" %}</a></li>
<li><a class="dropdown-item" href="{% url 'blog:category_list' %}">{% translate "category list" %}</a></li> <li><a class="dropdown-item" href="{% url 'blog:browse' %}">{% translate "Browse" %}</a></li>
</ul> </ul>
</li> </li>
<li class="nav-item dropdown"> <li class="nav-item dropdown">