From a877a7024040f8294c872ad544b681183fe29e00 Mon Sep 17 00:00:00 2001
From: "jindra12.underdark" <jindra12.underdark@gmail.com>
Date: Fri, 21 Apr 2023 01:59:39 +0200
Subject: [PATCH] Add footer links to uniweb + districts

TODO: add styling to senate subproject
---
 .../0109_districthomepage_footer_links.py     | 61 +++++++++++++++++++
 district/models.py                            | 10 ++-
 district/templates/district/base.html         |  4 ++
 .../0006_senatehomepage_footer_links.py       | 61 +++++++++++++++++++
 senate/models.py                              | 10 ++-
 senate/templates/senate/base.html             |  3 +
 shared/blocks.py                              | 23 ++++++-
 shared/models.py                              | 22 ++++++-
 .../shared/blocks/footer_links_block.html     |  9 +++
 .../0042_uniwebhomepage_footer_links.py       | 61 +++++++++++++++++++
 uniweb/models.py                              |  9 ++-
 uniweb/templates/uniweb/base.html             |  3 +
 12 files changed, 268 insertions(+), 8 deletions(-)
 create mode 100644 district/migrations/0109_districthomepage_footer_links.py
 create mode 100644 senate/migrations/0006_senatehomepage_footer_links.py
 create mode 100644 shared/templates/shared/blocks/footer_links_block.html
 create mode 100644 uniweb/migrations/0042_uniwebhomepage_footer_links.py

diff --git a/district/migrations/0109_districthomepage_footer_links.py b/district/migrations/0109_districthomepage_footer_links.py
new file mode 100644
index 00000000..a0426d47
--- /dev/null
+++ b/district/migrations/0109_districthomepage_footer_links.py
@@ -0,0 +1,61 @@
+# Generated by Django 4.1.8 on 2023-04-20 21:55
+
+import wagtail.blocks
+import wagtail.fields
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("district", "0108_alter_districtcenterpage_content_and_more"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="districthomepage",
+            name="footer_links",
+            field=wagtail.fields.StreamField(
+                [
+                    (
+                        "footer_links",
+                        wagtail.blocks.StructBlock(
+                            [
+                                (
+                                    "label",
+                                    wagtail.blocks.CharBlock(
+                                        label="Titulek zápatí", required=True
+                                    ),
+                                ),
+                                (
+                                    "items",
+                                    wagtail.blocks.ListBlock(
+                                        wagtail.blocks.StructBlock(
+                                            [
+                                                (
+                                                    "url",
+                                                    wagtail.blocks.URLBlock(
+                                                        label="Odkaz"
+                                                    ),
+                                                ),
+                                                (
+                                                    "text",
+                                                    wagtail.blocks.CharBlock(
+                                                        label="Text v odkazu"
+                                                    ),
+                                                ),
+                                            ]
+                                        ),
+                                        label="Odkazy",
+                                        required=True,
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                use_json_field=True,
+                verbose_name="Odkazy v zápatí webu",
+            ),
+        ),
+    ]
diff --git a/district/models.py b/district/models.py
index 54e42536..f7f75892 100644
--- a/district/models.py
+++ b/district/models.py
@@ -40,6 +40,7 @@ from shared.blocks import (
     ButtonGroupBlock,
     ChartBlock,
     FigureBlock,
+    FooterLinksBlock,
     FullSizeHeaderBlock,
     HeadlineBlock,
     YouTubeVideoBlock,
@@ -49,6 +50,7 @@ from shared.models import (
     ArticleMixin,
     ExtendedMetadataHomePageMixin,
     ExtendedMetadataPageMixin,
+    FooterMixin,
     MenuMixin,
     SubpageMixin,
 )
@@ -66,7 +68,12 @@ CONTENT_BLOCKS = DEFAULT_CONTENT_BLOCKS + [
 
 
 class DistrictHomePage(
-    MenuMixin, ExtendedMetadataHomePageMixin, MetadataPageMixin, CalendarMixin, Page
+    MenuMixin,
+    ExtendedMetadataHomePageMixin,
+    MetadataPageMixin,
+    CalendarMixin,
+    FooterMixin,
+    Page,
 ):
     ### FIELDS
 
@@ -267,6 +274,7 @@ class DistrictHomePage(
             ],
             gettext_lazy("Nastavení lišty s kalendářem a mapou"),
         ),
+        FieldPanel("footer_links"),
         FieldPanel("fallback_image"),
     ]
 
diff --git a/district/templates/district/base.html b/district/templates/district/base.html
index 360bdcf8..35fc5e4c 100644
--- a/district/templates/district/base.html
+++ b/district/templates/district/base.html
@@ -287,6 +287,10 @@
                 </ul>
               </ui-footer-collapsible>
             </div>
+
+            {% if page.root_page.footer_links %}
+              {% include_block page.root_page.footer_links with container="py-4 lg:py-0 border-t border-grey-400 lg:border-t-0" %}
+            {% endif %}
           </section>
 
           <section class="footer__social lg:text-right">
diff --git a/senate/migrations/0006_senatehomepage_footer_links.py b/senate/migrations/0006_senatehomepage_footer_links.py
new file mode 100644
index 00000000..c09a5f8c
--- /dev/null
+++ b/senate/migrations/0006_senatehomepage_footer_links.py
@@ -0,0 +1,61 @@
+# Generated by Django 4.1.8 on 2023-04-20 21:55
+
+import wagtail.blocks
+import wagtail.fields
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("senate", "0005_alter_senatehomepage_candidates_and_more"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="senatehomepage",
+            name="footer_links",
+            field=wagtail.fields.StreamField(
+                [
+                    (
+                        "footer_links",
+                        wagtail.blocks.StructBlock(
+                            [
+                                (
+                                    "label",
+                                    wagtail.blocks.CharBlock(
+                                        label="Titulek zápatí", required=True
+                                    ),
+                                ),
+                                (
+                                    "items",
+                                    wagtail.blocks.ListBlock(
+                                        wagtail.blocks.StructBlock(
+                                            [
+                                                (
+                                                    "url",
+                                                    wagtail.blocks.URLBlock(
+                                                        label="Odkaz"
+                                                    ),
+                                                ),
+                                                (
+                                                    "text",
+                                                    wagtail.blocks.CharBlock(
+                                                        label="Text v odkazu"
+                                                    ),
+                                                ),
+                                            ]
+                                        ),
+                                        label="Odkazy",
+                                        required=True,
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                use_json_field=True,
+                verbose_name="Odkazy v zápatí webu",
+            ),
+        ),
+    ]
diff --git a/senate/models.py b/senate/models.py
index 8b3facef..cc62e29b 100644
--- a/senate/models.py
+++ b/senate/models.py
@@ -8,6 +8,8 @@ from wagtail.images.edit_handlers import FieldPanel
 from wagtail.models import Page
 from wagtailmetadata.models import MetadataPageMixin
 
+from shared.blocks import FooterLinksBlock
+from shared.models import FooterMixin
 from tuning import admin_help
 
 
@@ -25,7 +27,7 @@ class PersonBlock(blocks.StructBlock):
         label = "osoba"
 
 
-class SenateHomePage(MetadataPageMixin, Page):
+class SenateHomePage(MetadataPageMixin, FooterMixin, Page):
     ### FIELDS
 
     senators = StreamField(
@@ -70,7 +72,11 @@ class SenateHomePage(MetadataPageMixin, Page):
         ),
     ]
 
-    settings_panels = [FieldPanel("matomo_id"), CommentPanel()]
+    settings_panels = [
+        FieldPanel("matomo_id"),
+        FieldPanel("footer_links"),
+        CommentPanel(),
+    ]
 
     ### RELATIONS
 
diff --git a/senate/templates/senate/base.html b/senate/templates/senate/base.html
index bcbab584..14906311 100644
--- a/senate/templates/senate/base.html
+++ b/senate/templates/senate/base.html
@@ -69,6 +69,9 @@
                                     </div>
                                 </a>
                             </div>
+                            {% if page.footer_links %}
+                                {% include_block page.footer_links with container="col-sm-5 col-12" %}
+                            {% endif %}
                         </div>
                     </div>
                 </div>
diff --git a/shared/blocks.py b/shared/blocks.py
index 869a4555..db1c7339 100644
--- a/shared/blocks.py
+++ b/shared/blocks.py
@@ -730,7 +730,9 @@ class ChartRedmineIssueDataset(blocks.StructBlock):
         required=False,
     )
 
-    def _get_issues_url(self, value, project_id: typing.Union[None, str, list[str]] = None):
+    def _get_issues_url(
+        self, value, project_id: typing.Union[None, str, list[str]] = None
+    ):
         url = "https://redmine.pirati.cz/issues.json"
         params = [
             ("sort", "created_on"),
@@ -1042,6 +1044,25 @@ class ChartBlock(blocks.StructBlock):
 Zobrazí se tolik definovaných sloupců, kolik existuje skupin."""
 
 
+class FooterLinksBlock(blocks.StructBlock):
+    label = blocks.CharBlock(label="Titulek zápatí", required=True)
+    items = blocks.ListBlock(
+        blocks.StructBlock(
+            [
+                ("url", blocks.URLBlock(label="Odkaz")),
+                ("text", blocks.CharBlock(label="Text v odkazu")),
+            ]
+        ),
+        label="Odkazy",
+        required=True,
+    )
+
+    class Meta:
+        label = "Seznam odkazů v zápatí"
+        icon = "list-ul"
+        template = "shared/blocks/footer_links_block.html"
+
+
 DEFAULT_CONTENT_BLOCKS = [
     (
         "text",
diff --git a/shared/models.py b/shared/models.py
index 44924a50..5d63c346 100644
--- a/shared/models.py
+++ b/shared/models.py
@@ -6,7 +6,12 @@ from wagtail.admin.panels import FieldPanel, MultiFieldPanel, PublishingPanel
 from wagtail.fields import StreamField
 from wagtail.models import Page
 
-from shared.blocks import DEFAULT_CONTENT_BLOCKS, MenuItemBlock, MenuParentBlock
+from shared.blocks import (
+    DEFAULT_CONTENT_BLOCKS,
+    FooterLinksBlock,
+    MenuItemBlock,
+    MenuParentBlock,
+)
 
 logger = logging.getLogger(__name__)
 
@@ -192,3 +197,18 @@ class ExtendedMetadataPageMixin(models.Model):
             return super().get_meta_title()
 
         return f"{super().get_meta_title()} | {self.get_meta_title_suffix()}"
+
+
+class FooterMixin(models.Model):
+    footer_links = StreamField(
+        [
+            ("footer_links", FooterLinksBlock()),
+        ],
+        verbose_name="Odkazy v zápatí webu",
+        blank=True,
+        max_num=1,
+        use_json_field=True,
+    )
+
+    class Meta:
+        abstract = True
diff --git a/shared/templates/shared/blocks/footer_links_block.html b/shared/templates/shared/blocks/footer_links_block.html
new file mode 100644
index 00000000..ebc55cb0
--- /dev/null
+++ b/shared/templates/shared/blocks/footer_links_block.html
@@ -0,0 +1,9 @@
+<div class="{{ container }}">
+    <ui-footer-collapsible label="{{ self.label }}">
+        <ul class="mt-6 space-y-2 text-grey-200">
+        {% for item in self.items %}
+            <li><a href="{{ item.url }}">{{ item.text }}</a></li>
+        {% endfor %}
+        </ul>
+    </ui-footer-collapsible>
+</div>
diff --git a/uniweb/migrations/0042_uniwebhomepage_footer_links.py b/uniweb/migrations/0042_uniwebhomepage_footer_links.py
new file mode 100644
index 00000000..0e5c44f7
--- /dev/null
+++ b/uniweb/migrations/0042_uniwebhomepage_footer_links.py
@@ -0,0 +1,61 @@
+# Generated by Django 4.1.8 on 2023-04-20 21:55
+
+import wagtail.blocks
+import wagtail.fields
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("uniweb", "0041_alter_uniwebflexiblepage_content_and_more"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="uniwebhomepage",
+            name="footer_links",
+            field=wagtail.fields.StreamField(
+                [
+                    (
+                        "footer_links",
+                        wagtail.blocks.StructBlock(
+                            [
+                                (
+                                    "label",
+                                    wagtail.blocks.CharBlock(
+                                        label="Titulek zápatí", required=True
+                                    ),
+                                ),
+                                (
+                                    "items",
+                                    wagtail.blocks.ListBlock(
+                                        wagtail.blocks.StructBlock(
+                                            [
+                                                (
+                                                    "url",
+                                                    wagtail.blocks.URLBlock(
+                                                        label="Odkaz"
+                                                    ),
+                                                ),
+                                                (
+                                                    "text",
+                                                    wagtail.blocks.CharBlock(
+                                                        label="Text v odkazu"
+                                                    ),
+                                                ),
+                                            ]
+                                        ),
+                                        label="Odkazy",
+                                        required=True,
+                                    ),
+                                ),
+                            ]
+                        ),
+                    )
+                ],
+                blank=True,
+                use_json_field=True,
+                verbose_name="Odkazy v zápatí webu",
+            ),
+        ),
+    ]
diff --git a/uniweb/models.py b/uniweb/models.py
index 70f746cb..423ad048 100644
--- a/uniweb/models.py
+++ b/uniweb/models.py
@@ -25,18 +25,19 @@ from wagtail.models import Page
 from wagtailmetadata.models import MetadataPageMixin
 
 from calendar_utils.models import CalendarMixin
-from shared.blocks import ChartBlock
+from shared.blocks import ChartBlock, FooterLinksBlock
 from shared.const import RICH_TEXT_DEFAULT_FEATURES
 from shared.models import (
     ArticleMixin,
     ExtendedMetadataHomePageMixin,
     ExtendedMetadataPageMixin,
+    FooterMixin,
     SubpageMixin,
 )
 from shared.utils import make_promote_panels, strip_all_html_tags, trim_to_length
 from tuning import admin_help
 
-from .blocks import PeopleGroupListBlock, PersonCustomPositionBlock, PersonUrlBlock
+from .blocks import PeopleGroupListBlock, PersonUrlBlock
 from .constants import (
     ALIGN_CHOICES,
     ALIGN_CSS,
@@ -300,7 +301,7 @@ class UniwebArticleTag(TaggedItemBase):
 
 
 class UniwebHomePage(
-    Page, ExtendedMetadataHomePageMixin, MetadataPageMixin, CalendarMixin
+    Page, ExtendedMetadataHomePageMixin, MetadataPageMixin, CalendarMixin, FooterMixin
 ):
     ### FIELDS
 
@@ -330,6 +331,7 @@ class UniwebHomePage(
     )
 
     ### Footer
+
     show_logo = models.BooleanField(
         "zobrazit logo", default=True, help_text="Zobrazit logo"
     )
@@ -369,6 +371,7 @@ class UniwebHomePage(
                 FieldPanel("show_social_links"),
                 FieldPanel("show_pirate_buttons"),
                 FieldPanel("footer_extra_content"),
+                FieldPanel("footer_links"),
             ],
             "nastavení patičky",
         ),
diff --git a/uniweb/templates/uniweb/base.html b/uniweb/templates/uniweb/base.html
index 733e7c91..7522bd1a 100644
--- a/uniweb/templates/uniweb/base.html
+++ b/uniweb/templates/uniweb/base.html
@@ -133,6 +133,9 @@
               {% endif %}
             </div>
           </section>
+          {% if page.root_page.footer_links %}
+            {% include_block page.root_page.footer_links with container="flex flex-col md:flex-row lg:flex-col lg:items-end space-y-2 md:space-y-0 md:space-x-2 lg:space-x-0 lg:space-y-2" %}
+          {% endif %}
         </div>
       </div>
     </ui-app>
-- 
GitLab