basic blog article loading

This commit is contained in:
Christoph J. Scherr 2023-06-03 21:36:27 +02:00
parent 6d2189170a
commit 4cfb75d563
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
12 changed files with 146 additions and 10 deletions

View File

@ -12,5 +12,5 @@ class BlogPostAdmin(admin.ModelAdmin):
""" """
The admin model for BlogPost The admin model for BlogPost
""" """
list_display = ["title_en", "subtitle_en", "title_de", "subtitle_de", "date", "category", "suburl"] list_display = ["title_en", "subtitle_en", "title_de", "subtitle_de", "date", "category", "slug", "suburl", "public"]
date_hierarchy = "date" date_hierarchy = "date"

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.19 on 2023-06-03 18:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('blog', '0002_blogpost_category'),
]
operations = [
migrations.AddField(
model_name='blogpost',
name='public',
field=models.BooleanField(default=True),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.2.19 on 2023-06-03 19:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('blog', '0003_blogpost_public'),
]
operations = [
migrations.AddField(
model_name='blogpost',
name='slug',
field=models.SlugField(default='test'),
preserve_default=False,
),
]

View File

@ -16,3 +16,5 @@ class BlogPost(Searchable):
body = models.TextField() body = models.TextField()
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True) category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
thumbnail = models.ImageField(blank=True) thumbnail = models.ImageField(blank=True)
public = models.BooleanField(default=True)
slug = models.SlugField()

View File

@ -0,0 +1,53 @@
{% extends 'base.html' %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% block languagecode %}{{ LANGUAGE_CODE }}{% endblock languagecode %}
{% block title %}{% translate "cscherr.de" %} - {% translate "Blog" %}{% endblock title %}
{% block nav %}
{% include 'blog/nav.html' %}
{% endblock nav %}
{% block main %}
<div class="container-xl">
<div class="jumbotron text-center">
<h1>{{ post.title }}</h1>
<p>{% translate "Blog" %}</p>
</div>
<div class="row text-center">
<div class="col mx-3 my-5">
<h3>{% translate "Writeups" %}</h3>
<p>
{% blocktranslate %}
Whenever I discover some interesting security thing, I will post a writeup here.
{% endblocktranslate %}
</p>
</div>
<div class="col mx-3 my-5">
<h3>{% translate "Open Source" %}</h3>
{% blocktranslate %}
If something comes up, I may post Linux guides or my thoughts on current processes here.
{% endblocktranslate %}
</div>
<div class="col mx-3 my-5">
<h3>{% translate "Selfhosting" %}</h3>
{% blocktranslate %}
Selfhosting is something that I'm really fond of. There will be guides and thoughts about that too
{% endblocktranslate %}
</div>
<div class="col mx-3 my-5">
<h3>{% translate "Anything Really" %}</h3>
{% blocktranslate %}
This is my personal Blog after all, I will put here whatever I want and you can't stop me.
{% endblocktranslate %}
</div>
</div>
<div class="container text-center">
test
<a href="{% url 'blog:post' "test" "test" %}">sus</a>
</div>
<div class="container text-center jumbotron my-3">
<h1 class="my-4">{% translate "Looking for anything specific?" %}</h1>
{% include 'main_search_form.html' %}
</div>
{% include 'blog/featured.html' %}
</div>
{% endblock main %}

View File

@ -40,6 +40,10 @@
{% endblocktranslate %} {% endblocktranslate %}
</div> </div>
</div> </div>
<div class="container text-center">
test
<a href="{% url 'blog:post' "test" "test" %}">sus</a>
</div>
<div class="container text-center jumbotron my-3"> <div class="container text-center jumbotron my-3">
<h1 class="my-4">{% translate "Looking for anything specific?" %}</h1> <h1 class="my-4">{% translate "Looking for anything specific?" %}</h1>
{% include 'main_search_form.html' %} {% include 'main_search_form.html' %}

View File

@ -15,7 +15,7 @@
<a class="nav-link" aria-current="page" href="{% url 'start:index' %}">{% translate "Start" %}</a> <a class="nav-link" aria-current="page" href="{% url 'start:index' %}">{% translate "Start" %}</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" href="{% url 'BlogIndex' %}">{% translate "Blog" %}</a> <a class="nav-link" href="{% url 'blog:index' %}">{% translate "Blog" %}</a>
</li> </li>
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
@ -23,6 +23,7 @@
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="http://localhost:8082" target="_blank">DB</a></li> <li><a class="dropdown-item" href="http://localhost:8082" target="_blank">DB</a></li>
<li><a class="dropdown-item" href="{% url 'admin:index' %}" target="_blank">Admin</a></li>
<li><hr class="dropdown-divider"></li> <li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li>
</ul> </ul>

View File

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

View File

@ -1,8 +1,14 @@
from django.shortcuts import render from django.shortcuts import Http404, HttpResponse, get_object_or_404, render
from django.utils.translation import get_language
from django.views.generic import TemplateView, DetailView, ListView, View from django.views.generic import TemplateView, DetailView, ListView, View
from .models import BlogPost, Category
from start.views import SearchableView from start.views import SearchableView
import logging
logger = logging.getLogger(__name__)
class Index(TemplateView, SearchableView): class Index(TemplateView, SearchableView):
""" """
The index page of the gawa/blog app. The index page of the gawa/blog app.
@ -17,13 +23,38 @@ class Post(DetailView):
""" """
Main page of a blog post Main page of a blog post
""" """
pass
model=BlogPost
template_name = "blog/blogpost.html"
context_object_name = "post"
def get_object(self, queryset=None):
obj = get_object_or_404(
BlogPost,
category__slug=self.kwargs['category'], # first slug is category
slug=self.kwargs['slug'] # second slug is article itself
)
logger.critical("hello world")
match get_language():
case 'de':
obj['title'] = obj['title_de']
case 'en':
obj['title'] = obj['title_en']
case _:
# this should not happen, but who knows what dumb stuff users will come up with
logger.warning("article for unsupported language was requested")
return obj
class CategoryList(ListView): class CategoryList(ListView):
""" """
Scroll through a list of blog Categories Scroll through a list of blog Categories
""" """
pass
model=Category
template_name = "blog/categories.html"
context_object_name = "categories"
class ArticleList(ListView): class ArticleList(ListView):
""" """
@ -32,4 +63,7 @@ class ArticleList(ListView):
There should also be some kind of filter, for category and date. There should also be some kind of filter, for category and date.
Of course, Articles will also show up in the MainSearchView Of course, Articles will also show up in the MainSearchView
""" """
pass
model=BlogPost
template_name = "blog/posts.html"
context_object_name = "posts"

View File

@ -25,5 +25,5 @@ urlpatterns = [
urlpatterns += i18n_patterns( urlpatterns += i18n_patterns(
path("", include("start.urls")), path("", include("start.urls")),
path("blog/", include("blog.urls")), path("blog/", include("blog.urls")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls, name="admin"),
) )

View File

@ -2,5 +2,5 @@
<form class="d-flex" role="search" action="{% url 'start:search' %}" method="GET"> <form class="d-flex" role="search" action="{% url 'start:search' %}" method="GET">
{#{ MainSearchForm }#} {#{ MainSearchForm }#}
<input type="search" name="search" class="form-control me-2" aria-label="Search" placeholder="Suchen" required id="id_search"> <input type="search" name="search" class="form-control me-2" aria-label="Search" placeholder="Suchen" required id="id_search">
<button class="btn bg-success" type="submit">{% translate "Suchen" %}</button> <button class="btn bg-primary fw-bold" type="submit">{% translate "Suchen" %}</button>
</form> </form>

View File

@ -15,7 +15,7 @@
<a class="nav-link active" aria-current="page" href="{% url 'start:index' %}">{% translate "Start" %}</a> <a class="nav-link active" aria-current="page" href="{% url 'start:index' %}">{% translate "Start" %}</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'BlogIndex' %}">{% translate "Blog" %}</a> <a class="nav-link" href="{% url 'blog:index' %}">{% translate "Blog" %}</a>
</li> </li>
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
@ -23,6 +23,7 @@
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="http://localhost:8082" target="_blank">DB</a></li> <li><a class="dropdown-item" href="http://localhost:8082" target="_blank">DB</a></li>
<li><a class="dropdown-item" href="{% url 'admin:index' %}" target="_blank">Admin</a></li>
<li><hr class="dropdown-divider"></li> <li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li>
</ul> </ul>