From 661d7cbf546630fc6e512b6e2175d8273f2800fb Mon Sep 17 00:00:00 2001
From: SofianeLasri <alasri250@gmail.com>
Date: Tue, 13 Jun 2023 23:01:56 +0200
Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20la=20page=20des=20articles?=
 =?UTF-8?q?.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 WSR/static/scss/components.scss | 16 +++++++++-------
 WSR/templates/articles.html     | 29 +++++++++++++++++++++++++++++
 WSR/templates/base.html         |  2 +-
 WSR/templates/home.html         |  2 +-
 WSR/views.py                    | 14 ++++++++++++++
 WSR_website/urls.py             |  1 +
 6 files changed, 55 insertions(+), 9 deletions(-)
 create mode 100644 WSR/templates/articles.html

diff --git a/WSR/static/scss/components.scss b/WSR/static/scss/components.scss
index 17b30f0..0595905 100644
--- a/WSR/static/scss/components.scss
+++ b/WSR/static/scss/components.scss
@@ -167,19 +167,19 @@
     padding: 32px 24px;
     background-color: $white;
     width: 1076px;
-
-    .news-cards {
-      display: grid;
-      grid-template-columns: repeat(3, 1fr);
-      gap: map-get($spacers, 3);
-    }
   }
 }
 
+.news-cards {
+  display: grid;
+  grid-template-columns: repeat(3, 1fr);
+  gap: map-get($spacers, 3);
+}
+
 .news-card {
   display: flex;
   flex-direction: column;
-  width: 332px;
+  width: auto;
   text-decoration: none;
   color: $black;
 
@@ -260,6 +260,7 @@ footer {
         color: $white;
         font-size: 1.4rem;
       }
+
       .desc {
         color: $light-gray;
         line-height: 1;
@@ -298,6 +299,7 @@ footer {
           filter: brightness(0);
         }
       }
+
       .desc {
         color: $dark-gray;
       }
diff --git a/WSR/templates/articles.html b/WSR/templates/articles.html
new file mode 100644
index 0000000..5a82e97
--- /dev/null
+++ b/WSR/templates/articles.html
@@ -0,0 +1,29 @@
+{% extends 'base.html' %}
+{% load static %}
+
+{% block title %}WSR - Liste des articles{% endblock %}
+
+{% block content %}
+    <div class="container mt-4">
+        <div class="p-4 bg-white">
+            <h4 class="eurostile title">Articles de blog</h4>
+            <p>Reste informé de toutes les actualités des WSR ! (déso j'ai pas d'idées, il est tard)</p>
+
+            <div class="news-cards">
+                {% for article in articles %}
+                    <a class="news-card" href="{% url 'article' id=article.id %}">
+                        <div class="header">
+                            <div class="logo">
+                                <img src="{% static 'images/WSR.png' %}" alt="Logo WSR">
+                            </div>
+                        </div>
+                        <div class="mt-3">
+                            <div class="eurostile">{{ article.title }}</div>
+                            <div class="desc">{{ article.summary }}</div>
+                        </div>
+                    </a>
+                {% endfor %}
+            </div>
+        </div>
+    </div>
+{% endblock %}
\ No newline at end of file
diff --git a/WSR/templates/base.html b/WSR/templates/base.html
index 1d17f3d..a3c8980 100644
--- a/WSR/templates/base.html
+++ b/WSR/templates/base.html
@@ -13,7 +13,7 @@
 </head>
 <body>
 <header class="container">
-    <a class="logo" href="/">
+    <a class="logo" href="{% url 'home' %}">
         <img src="{% static 'images/WSR.png' %}" alt="Logo WSR">
     </a>
     <nav class="navbar">
diff --git a/WSR/templates/home.html b/WSR/templates/home.html
index 573246c..e0011c7 100644
--- a/WSR/templates/home.html
+++ b/WSR/templates/home.html
@@ -83,7 +83,7 @@
                     {% endfor %}
                 </div>
                 <div class="d-flex justify-content-end">
-                    <a class="btn" href="#">Voir tout</a>
+                    <a class="btn" href="{% url 'articles' %}">Voir tout</a>
                 </div>
             </div>
             <div id="racesResultsContainer" style="display: none;">
diff --git a/WSR/views.py b/WSR/views.py
index fbad81c..7d08e50 100644
--- a/WSR/views.py
+++ b/WSR/views.py
@@ -64,6 +64,20 @@ def home(request):
     )
 
 
+def articles(request):
+    articles = Article.objects.order_by('-publication_date').all()
+    for article in articles:
+        article.summary = ' '.join(article.content.split()[:14]) + '...'
+
+    return render(
+        request,
+        'articles.html',
+        {
+            "articles": articles
+        }
+    )
+
+
 def view_article(request, id):
     article = Article.objects.get(id=id)
     md = markdown.Markdown()
diff --git a/WSR_website/urls.py b/WSR_website/urls.py
index 4779a32..ed10312 100644
--- a/WSR_website/urls.py
+++ b/WSR_website/urls.py
@@ -25,6 +25,7 @@ urlpatterns = [
     path('admin/', admin.site.urls),
     path('', views.home, name="home"),
     path('article/<int:id>', views.view_article, name="article"),
+    path('articles', views.articles, name="articles"),
     path('races-types', views.races_types, name="races_types"),
     path('vehicles', views.vehicles, name="vehicles"),
     path('seasons', views.seasons, name="seasons")
-- 
GitLab