basic blog article loading
This commit is contained in:
parent
6d2189170a
commit
4cfb75d563
|
@ -12,5 +12,5 @@ class BlogPostAdmin(admin.ModelAdmin):
|
|||
"""
|
||||
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"
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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,
|
||||
),
|
||||
]
|
|
@ -16,3 +16,5 @@ class BlogPost(Searchable):
|
|||
body = models.TextField()
|
||||
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
|
||||
thumbnail = models.ImageField(blank=True)
|
||||
public = models.BooleanField(default=True)
|
||||
slug = models.SlugField()
|
||||
|
|
|
@ -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 %}
|
|
@ -40,6 +40,10 @@
|
|||
{% 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' %}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<a class="nav-link" aria-current="page" href="{% url 'start:index' %}">{% translate "Start" %}</a>
|
||||
</li>
|
||||
<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 class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
|
@ -23,6 +23,7 @@
|
|||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<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><a class="dropdown-item" href="#">Something else here</a></li>
|
||||
</ul>
|
||||
|
|
|
@ -2,6 +2,10 @@ from django.urls import path
|
|||
|
||||
from . import views
|
||||
|
||||
app_name: str = "blog"
|
||||
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"),
|
||||
]
|
||||
|
|
|
@ -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 .models import BlogPost, Category
|
||||
|
||||
from start.views import SearchableView
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Index(TemplateView, SearchableView):
|
||||
"""
|
||||
The index page of the gawa/blog app.
|
||||
|
@ -17,13 +23,38 @@ class Post(DetailView):
|
|||
"""
|
||||
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):
|
||||
"""
|
||||
Scroll through a list of blog Categories
|
||||
"""
|
||||
pass
|
||||
|
||||
model=Category
|
||||
template_name = "blog/categories.html"
|
||||
context_object_name = "categories"
|
||||
|
||||
class ArticleList(ListView):
|
||||
"""
|
||||
|
@ -32,4 +63,7 @@ class ArticleList(ListView):
|
|||
There should also be some kind of filter, for category and date.
|
||||
Of course, Articles will also show up in the MainSearchView
|
||||
"""
|
||||
pass
|
||||
|
||||
model=BlogPost
|
||||
template_name = "blog/posts.html"
|
||||
context_object_name = "posts"
|
||||
|
|
|
@ -25,5 +25,5 @@ urlpatterns = [
|
|||
urlpatterns += i18n_patterns(
|
||||
path("", include("start.urls")),
|
||||
path("blog/", include("blog.urls")),
|
||||
path('admin/', admin.site.urls),
|
||||
path('admin/', admin.site.urls, name="admin"),
|
||||
)
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
<form class="d-flex" role="search" action="{% url 'start:search' %}" method="GET">
|
||||
{#{ MainSearchForm }#}
|
||||
<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>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<a class="nav-link active" aria-current="page" href="{% url 'start:index' %}">{% translate "Start" %}</a>
|
||||
</li>
|
||||
<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 class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
|
@ -23,6 +23,7 @@
|
|||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<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><a class="dropdown-item" href="#">Something else here</a></li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue