Archived
1
Fork 0
This commit is contained in:
Edgar P. Burkhart 2024-06-12 18:47:41 +02:00
parent 92f6fe06a4
commit a7bad9aa3b
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
11 changed files with 217 additions and 4 deletions

0
lps/blog/__init__.py Normal file
View file

6
lps/blog/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class BlogConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "blog"

View file

@ -0,0 +1,57 @@
# Generated by Django 5.0.6 on 2024-06-12 16:15
import django.db.models.deletion
import wagtail.fields
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("wagtailcore", "0093_uploadedfile"),
("wagtailimages", "0026_delete_uploadedimage"),
]
operations = [
migrations.CreateModel(
name="BlogPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
(
"introduction",
models.TextField(blank=True, help_text="Introduction de l'article"),
),
("body", wagtail.fields.RichTextField(blank=True)),
(
"date_published",
models.DateField(verbose_name="Date de publication de l'article"),
),
(
"image",
models.ForeignKey(
blank=True,
help_text="Image de l'article",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.image",
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page",),
),
]

View file

@ -0,0 +1,50 @@
# Generated by Django 5.0.6 on 2024-06-12 16:25
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("blog", "0001_initial"),
("wagtailcore", "0093_uploadedfile"),
("wagtailimages", "0026_delete_uploadedimage"),
]
operations = [
migrations.CreateModel(
name="BlogIndexPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
(
"introduction",
models.TextField(blank=True, help_text="Description de la page"),
),
(
"image",
models.ForeignKey(
blank=True,
help_text="Image du blog",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.image",
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page",),
),
]

View file

54
lps/blog/models.py Normal file
View file

@ -0,0 +1,54 @@
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
class BlogPage(Page):
introduction = models.TextField(help_text="Introduction de l'article", blank=True)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Image de l'article",
)
body = RichTextField(blank=True)
date_published = models.DateField("Date de publication de l'article")
content_panels = Page.content_panels + [
FieldPanel("introduction"),
FieldPanel("image"),
FieldPanel("body"),
FieldPanel("date_published"),
]
class BlogIndexPage(Page):
introduction = models.TextField(help_text="Description de la page", blank=True)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Image du blog",
)
content_panels = Page.content_panels + [
FieldPanel("introduction"),
FieldPanel("image"),
]
subpage_types = ["BlogPage"]
def children(self):
return self.get_children().specific().live()
def get_context(self, request):
context = super().get_context(request)
context["posts"] = (
BlogPage.objects.descendant_of(self).live().order_by("-date_published")
)
return context

View file

@ -0,0 +1,34 @@
{% extends "base.html" %}
{% load wagtailcore_tags navigation_tags wagtailimages_tags %}
{% block content %}
<h1>{{ page.title }}</h1>
{% if page.introduction or page.image %}
<section>
{% if page.introduction %}<p>{{ page.introduction }}</p>{% endif %}
{% if page.image %}
{% srcset_image page.image width-{510,700,950,1200,1450} %}
{% endif %}
</section>
{% endif %}
<section class="grid blog-grid">
{% for blog in posts %}
<div>
<article>
<header>
<strong><a href="{% pageurl blog %}">{{ blog.title }}</a></strong>
</header>
{% if blog.image %}
{% srcset_image blog.image width-{510,700,950,1200,1450} %}
{% else %}
{{ blog.introduction }}
{% endif %}
<footer>
{{ blog.date_published }}
</footer>
</article>
</div>
{% empty %}
Aucun article n'a été publié ici pour le moment.
{% endfor %}
</section>
{% endblock %}

View file

@ -0,0 +1,6 @@
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block content %}
<h1>{{ page.title }}</h1>
{{ page.body|richtext }}
{% endblock %}

View file

@ -26,6 +26,7 @@ BASE_DIR = os.path.dirname(PROJECT_DIR)
INSTALLED_APPS = [
"base",
"home",
"blog",
"search",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",

View file

@ -9,3 +9,8 @@ h1, h2, h3, h4, h5, h6 {
img {
width: 100%;
}
.blog-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

View file

@ -25,7 +25,7 @@
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
<link rel="preconnect" href="https://cdn.jsdelivr.net/">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css" />
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.jade.min.css" />
<link href="https://cdn.jsdelivr.net/npm/remixicon@4.2.0/fonts/remixicon.css"
rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="{% static 'css/lps.css' %}">
@ -33,13 +33,13 @@
</head>
<body>
{% wagtailuserbar %}
<header>
<header class="container">
{% include "nav.html" %}
</header>
<main>
<main class="container">
{% block content %}{% endblock %}
</main>
<footer>
<footer class="container">
{% include "footer.html" %}
</footer>
{# Global javascript #}