From dc75e84a7f7f472f8ab1551cd949dad80033b9c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Fri, 17 Apr 2020 22:57:28 +0200
Subject: [PATCH] Senator: News link on homepage

---
 senator/models.py                                | 13 +++++++++++++
 senator/templates/senator/senator_home_page.html |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/senator/models.py b/senator/models.py
index efe69180..878a08b8 100644
--- a/senator/models.py
+++ b/senator/models.py
@@ -45,6 +45,7 @@ class SenatorHomePage(Page):
 
     def get_context(self, request):
         context = super().get_context(request)
+
         articles = (
             self.get_descendants()
             .type(SenatorNewsPage)
@@ -52,6 +53,18 @@ class SenatorHomePage(Page):
             .order_by("-senatornewspage__date")[:3]
         )
         context["articles"] = articles
+
+        try:
+            context["news_url"] = (
+                self.get_children()
+                .type(SenatorNewsIndexPage)
+                .live()
+                .get()
+                .get_url(request)
+            )
+        except SenatorNewsIndexPage.DoesNotExist:
+            context["news_url"] = "#"
+
         return context
 
 
diff --git a/senator/templates/senator/senator_home_page.html b/senator/templates/senator/senator_home_page.html
index d4157134..b856c05b 100644
--- a/senator/templates/senator/senator_home_page.html
+++ b/senator/templates/senator/senator_home_page.html
@@ -183,7 +183,11 @@
               </div>
             </div>
             <div class="w-separator type_invisible size_large thick_1 style_solid color_border cont_none"><span class="w-separator-h"></span></div>
-            <div class="w-btn-wrapper align_center"><a class="w-btn style_raised color_contrast icon_atright outlined-black" href="https://lukaswagenknecht.cz/novinky/" style="font-size:20px;"><i class="fa fa-arrow-right"></i><span class="w-btn-label">Všechny novinky</span></a></div>
+            <div class="w-btn-wrapper align_center">
+              <a class="w-btn style_raised color_contrast icon_atright outlined-black" href="{{ news_url }}" style="font-size:20px;">
+                <i class="fa fa-arrow-right"></i><span class="w-btn-label">Všechny novinky</span>
+              </a>
+            </div>
           </div>
         </div>
       </div>
-- 
GitLab