From 4f354c0014b621281af5465e9ad9cc2a2c3cb068 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Thu, 26 Nov 2020 11:26:47 +0100 Subject: [PATCH] Display an index page below the articles without abstract --- articles/context_processors.py | 2 +- articles/static/style.css | 4 ++ .../templates/articles/article_detail.html | 4 +- articles/templates/articles/article_list.html | 43 +++++++++++-------- articles/templates/articles/base.html | 2 +- articles/views/html.py | 7 ++- 6 files changed, 38 insertions(+), 24 deletions(-) diff --git a/articles/context_processors.py b/articles/context_processors.py index 65b429d..022bde3 100644 --- a/articles/context_processors.py +++ b/articles/context_processors.py @@ -10,7 +10,7 @@ IGNORED_PATHS = [ def pages(request): if request.path in IGNORED_PATHS: return {} - return {"pages": Page.objects.filter(status=Article.PUBLISHED)} + return {"pages": Page.objects.filter(status=Article.PUBLISHED).exclude(position=0)} def drafts_count(request): diff --git a/articles/static/style.css b/articles/static/style.css index e4c6e4f..e4bfa9b 100644 --- a/articles/static/style.css +++ b/articles/static/style.css @@ -48,6 +48,10 @@ a { border-bottom: .3ex solid var(--accent); } +.index-page h2 { + margin-top: 2em; +} + .article-list h2 a { border-color: transparent; } diff --git a/articles/templates/articles/article_detail.html b/articles/templates/articles/article_detail.html index de72597..b517771 100644 --- a/articles/templates/articles/article_detail.html +++ b/articles/templates/articles/article_detail.html @@ -1,8 +1,6 @@ {% extends 'articles/base.html' %} -{% block title %} - {{ article.title }} -{% endblock %} +{% block title %}{{ article.title }} | {% endblock %} {% block content %}

{{ article.title }}{% if article.status != article.PUBLISHED %} diff --git a/articles/templates/articles/article_list.html b/articles/templates/articles/article_list.html index 448c330..ccde986 100644 --- a/articles/templates/articles/article_list.html +++ b/articles/templates/articles/article_list.html @@ -1,25 +1,26 @@ {% extends 'articles/base.html' %} -{% block title %} - {{ title_header }} -{% endblock %} +{% block title %}{% endblock %} {% block content %}

{{ blog_title }}{% if title %} · {{ title }}{% endif %}

- - + +
+

Blog posts

+
    + {% for article in articles %} +
  • + {% if article.published_at %} + + {% else %} + + {% endif %} + : {{ article.title }} +
  • + {% empty %} +
  • No article here. Come back later 🙂
  • + {% endfor %} +
+
+
+

{{ index_page.title }}

+
+ {{ index_page.get_formatted_content|safe }} +
+
{% endblock %} diff --git a/articles/templates/articles/base.html b/articles/templates/articles/base.html index 586c52b..73d04e0 100644 --- a/articles/templates/articles/base.html +++ b/articles/templates/articles/base.html @@ -4,7 +4,7 @@ - {% block title %}Home{% endblock %} | Gab's Notes + {% block title %}Home | {% endblock %}Gab's Notes diff --git a/articles/views/html.py b/articles/views/html.py index cdbb867..12d4764 100644 --- a/articles/views/html.py +++ b/articles/views/html.py @@ -9,6 +9,8 @@ from articles.models import Article, Page class BaseArticleListView(generic.ListView): + paginate_by = 10 + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["blog_title"] = settings.BLOG["title"] @@ -23,7 +25,10 @@ class ArticlesListView(BaseArticleListView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context["title_header"] = "Articles" + index_page = Page.objects.filter( + status=Article.PUBLISHED, position=0 + ).first() # type: Page + context["index_page"] = index_page return context