basic blog post view
This commit is contained in:
parent
90f69ab886
commit
f844fab25e
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 3.2.19 on 2023-06-16 20:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0008_auto_20230604_0156'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='blogpost',
|
||||
name='body',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='blogpost',
|
||||
name='body_de',
|
||||
field=models.TextField(default='Bis jetzt keine deutsche Übersetzung.'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='blogpost',
|
||||
name='body_en',
|
||||
field=models.TextField(default='No english translation yet.'),
|
||||
),
|
||||
]
|
|
@ -26,7 +26,8 @@ class BlogPost(Searchable):
|
|||
"""
|
||||
Should contain a blogpost
|
||||
"""
|
||||
body = models.TextField()
|
||||
body_en = models.TextField(default="No english translation yet.")
|
||||
body_de = models.TextField(default="Bis jetzt keine deutsche Übersetzung.")
|
||||
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
|
||||
thumbnail = models.ImageField(blank=True, upload_to="img/thumbnails")
|
||||
featured = models.BooleanField(default=False)
|
||||
|
|
|
@ -7,20 +7,63 @@
|
|||
{% include 'nav.html' %}
|
||||
{% endblock nav %}
|
||||
{% block headscripts %}
|
||||
<script type="text/javascript" id="MathJax-script" async
|
||||
src="https://cdn.jsdelivr.net/npm/mathjax@3.0.0/es5/tex-mml-chtml.js">
|
||||
</script>
|
||||
<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3.0.0/es5/tex-mml-chtml.js"></script>
|
||||
{% endblock headscripts %}
|
||||
{% block main %}
|
||||
<div class="container-xl">
|
||||
<div class="jumbotron text-center">
|
||||
<h1>{{ post.title }} <small class="">{{ post.subtitle }}</small></h1>
|
||||
<img src="{{ post.thumbnail.url }}" alt="thumbnail">
|
||||
<article>
|
||||
<div class="jumbotron my-5">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{% if LANGUAGE_CODE == "de" %}
|
||||
<h1 class="">{{ post.title_de }}<br>
|
||||
<small class="fs-4">{{ post.subtitle_de }}</small></h1><br>
|
||||
{% elif LANGUAGE_CODE == "en" %}
|
||||
<h1 class="">{{ post.title_en }}<br>
|
||||
<small class="fs-4">{{ post.subtitle_en }}</small></h1><br>
|
||||
{% else %}
|
||||
<h1 class="">{{ post.title_en }}<br>
|
||||
<small class="fs-4">{{ post.subtitle_en }}</small></h1><br>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="container">
|
||||
$$x=\frac{-b+\sqrt{b^2-4ac}}{2a}$$
|
||||
{{ post.body | safe }}
|
||||
</div>
|
||||
<div class="row align-items-center text-center">
|
||||
<div class="col">
|
||||
<picture>
|
||||
<img src="{{ post.thumbnail.url }}" alt="thumbnail" class="img-fluid">
|
||||
</picture>
|
||||
</div>
|
||||
<div class="col px-3">
|
||||
<div class="col">
|
||||
{% if LANGUAGE_CODE == "de" %}
|
||||
<p class="lead">{{ post.desc_de }}</p>
|
||||
{% elif LANGUAGE_CODE == "en" %}
|
||||
<p class="lead">{{ post.desc_en }}</p>
|
||||
{% else %}
|
||||
<p class="lead">{{ post.desc_en }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col">
|
||||
<p>{{ post.date }}</p>
|
||||
</div>
|
||||
<div class="col">
|
||||
<p>{{ post.category.name }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="my-5">
|
||||
{% if LANGUAGE_CODE == "de" %}
|
||||
{{ post.body_de | safe }}
|
||||
{% elif LANGUAGE_CODE == "en" %}
|
||||
{{ post.body_en | safe }}
|
||||
{% else %}
|
||||
{{ post.body_en | safe }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<hr>
|
||||
</article>
|
||||
</div>
|
||||
{% include 'blog/featured.html' %}
|
||||
</div>
|
||||
{% endblock main %}
|
||||
|
|
|
@ -39,30 +39,6 @@ class Post(DetailView):
|
|||
logger.debug(f"loaded featured posts: {context['featured_posts']}")
|
||||
return context
|
||||
|
||||
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
|
||||
)
|
||||
match get_language():
|
||||
case 'de':
|
||||
logger.debug("setting language unspecific attributes for language: de")
|
||||
obj.title = obj.title_de
|
||||
obj.subtitle = obj.subtitle_de
|
||||
obj.desc = obj.desc_de
|
||||
|
||||
case 'en':
|
||||
logger.debug("setting language unspecific attributes for language: en")
|
||||
obj.title = obj.title_en
|
||||
obj.subtitle = obj.subtitle_en
|
||||
obj.desc = obj.desc_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
|
||||
|
|
Loading…
Reference in New Issue