Add blog
This commit is contained in:
parent
92f6fe06a4
commit
a7bad9aa3b
11 changed files with 217 additions and 4 deletions
0
lps/blog/__init__.py
Normal file
0
lps/blog/__init__.py
Normal file
6
lps/blog/apps.py
Normal file
6
lps/blog/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class BlogConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "blog"
|
57
lps/blog/migrations/0001_initial.py
Normal file
57
lps/blog/migrations/0001_initial.py
Normal 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",),
|
||||||
|
),
|
||||||
|
]
|
50
lps/blog/migrations/0002_blogindexpage.py
Normal file
50
lps/blog/migrations/0002_blogindexpage.py
Normal 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",),
|
||||||
|
),
|
||||||
|
]
|
0
lps/blog/migrations/__init__.py
Normal file
0
lps/blog/migrations/__init__.py
Normal file
54
lps/blog/models.py
Normal file
54
lps/blog/models.py
Normal 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
|
34
lps/blog/templates/blog/blog_index_page.html
Normal file
34
lps/blog/templates/blog/blog_index_page.html
Normal 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 %}
|
6
lps/blog/templates/blog/blog_page.html
Normal file
6
lps/blog/templates/blog/blog_page.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load wagtailcore_tags wagtailimages_tags %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>{{ page.title }}</h1>
|
||||||
|
{{ page.body|richtext }}
|
||||||
|
{% endblock %}
|
|
@ -26,6 +26,7 @@ BASE_DIR = os.path.dirname(PROJECT_DIR)
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
"base",
|
"base",
|
||||||
"home",
|
"home",
|
||||||
|
"blog",
|
||||||
"search",
|
"search",
|
||||||
"wagtail.contrib.forms",
|
"wagtail.contrib.forms",
|
||||||
"wagtail.contrib.redirects",
|
"wagtail.contrib.redirects",
|
||||||
|
|
|
@ -9,3 +9,8 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
img {
|
img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.blog-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
|
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
|
||||||
<link rel="preconnect" href="https://cdn.jsdelivr.net/">
|
<link rel="preconnect" href="https://cdn.jsdelivr.net/">
|
||||||
<link rel="stylesheet"
|
<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"
|
<link href="https://cdn.jsdelivr.net/npm/remixicon@4.2.0/fonts/remixicon.css"
|
||||||
rel="stylesheet" />
|
rel="stylesheet" />
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'css/lps.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'css/lps.css' %}">
|
||||||
|
@ -33,13 +33,13 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% wagtailuserbar %}
|
{% wagtailuserbar %}
|
||||||
<header>
|
<header class="container">
|
||||||
{% include "nav.html" %}
|
{% include "nav.html" %}
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main class="container">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
<footer class="container">
|
||||||
{% include "footer.html" %}
|
{% include "footer.html" %}
|
||||||
</footer>
|
</footer>
|
||||||
{# Global javascript #}
|
{# Global javascript #}
|
||||||
|
|
Reference in a new issue