From f844fab25ef19a8528f2b554527365b4ed7c4e8d Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sat, 17 Jun 2023 00:38:45 +0200 Subject: [PATCH] basic blog post view --- .../migrations/0009_auto_20230616_2236.py | 27 ++++++++ gawa/blog/models.py | 3 +- gawa/blog/templates/blog/blogpost.html | 67 +++++++++++++++---- gawa/blog/views.py | 24 ------- 4 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 gawa/blog/migrations/0009_auto_20230616_2236.py diff --git a/gawa/blog/migrations/0009_auto_20230616_2236.py b/gawa/blog/migrations/0009_auto_20230616_2236.py new file mode 100644 index 0000000..a69017a --- /dev/null +++ b/gawa/blog/migrations/0009_auto_20230616_2236.py @@ -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.'), + ), + ] diff --git a/gawa/blog/models.py b/gawa/blog/models.py index b03d4d5..7e4ba13 100644 --- a/gawa/blog/models.py +++ b/gawa/blog/models.py @@ -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) diff --git a/gawa/blog/templates/blog/blogpost.html b/gawa/blog/templates/blog/blogpost.html index da1713b..94e40c4 100644 --- a/gawa/blog/templates/blog/blogpost.html +++ b/gawa/blog/templates/blog/blogpost.html @@ -7,20 +7,63 @@ {% include 'nav.html' %} {% endblock nav %} {% block headscripts %} - + {% endblock headscripts %} {% block main %}
-
-

{{ post.title }} {{ post.subtitle }}

- thumbnail -
-
- $$x=\frac{-b+\sqrt{b^2-4ac}}{2a}$$ - {{ post.body | safe }} -
- {% include 'blog/featured.html' %} +
+
+
+
+ {% if LANGUAGE_CODE == "de" %} +

{{ post.title_de }}
+ {{ post.subtitle_de }}


+ {% elif LANGUAGE_CODE == "en" %} +

{{ post.title_en }}
+ {{ post.subtitle_en }}


+ {% else %} +

{{ post.title_en }}
+ {{ post.subtitle_en }}


+ {% endif %} +
+
+
+
+ + thumbnail + +
+
+
+ {% if LANGUAGE_CODE == "de" %} +

{{ post.desc_de }}

+ {% elif LANGUAGE_CODE == "en" %} +

{{ post.desc_en }}

+ {% else %} +

{{ post.desc_en }}

+ {% endif %} +
+
+

{{ post.date }}

+
+
+

{{ post.category.name }}

+
+
+
+
+
+
+ {% if LANGUAGE_CODE == "de" %} + {{ post.body_de | safe }} + {% elif LANGUAGE_CODE == "en" %} + {{ post.body_en | safe }} + {% else %} + {{ post.body_en | safe }} + {% endif %} +
+
+
+{% include 'blog/featured.html' %} {% endblock main %} diff --git a/gawa/blog/views.py b/gawa/blog/views.py index f9090cb..024c0fc 100644 --- a/gawa/blog/views.py +++ b/gawa/blog/views.py @@ -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