From ccac35915f7bb034cbf8e8eb6e1ea6e1d19648cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Farka?= <stepanfarka11@gmail.com>
Date: Fri, 1 Apr 2022 16:16:26 +0200
Subject: [PATCH] [ADD] gallery blok to ArticleMixin

---
 .../0051_alter_districtarticlepage_content.py | 63 +++++++++++++++++++
 district/templates/district/base.html         |  1 +
 .../0026_alter_regionarticlepage_content.py   | 63 +++++++++++++++++++
 region/templates/region/base.html             |  1 +
 shared/blocks.py                              | 14 +++++
 shared/models.py                              | 10 ++-
 .../2.3.x/blocks/gallery_block.html           | 10 +++
 .../0023_alter_uniwebarticlepage_content.py   | 63 +++++++++++++++++++
 8 files changed, 223 insertions(+), 2 deletions(-)
 create mode 100644 district/migrations/0051_alter_districtarticlepage_content.py
 create mode 100644 region/migrations/0026_alter_regionarticlepage_content.py
 create mode 100644 shared/templates/styleguide/2.3.x/blocks/gallery_block.html
 create mode 100644 uniweb/migrations/0023_alter_uniwebarticlepage_content.py

diff --git a/district/migrations/0051_alter_districtarticlepage_content.py b/district/migrations/0051_alter_districtarticlepage_content.py
new file mode 100644
index 00000000..d89ac89a
--- /dev/null
+++ b/district/migrations/0051_alter_districtarticlepage_content.py
@@ -0,0 +1,63 @@
+# Generated by Django 4.0.3 on 2022-04-01 14:13
+
+import wagtail.core.blocks
+import wagtail.core.fields
+import wagtail.images.blocks
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("district", "0050_alter_districtcrossroadpage_content_and_more"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="districtarticlepage",
+            name="content",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "text",
+                        wagtail.core.blocks.RichTextBlock(
+                            features=[
+                                "h2",
+                                "h3",
+                                "h4",
+                                "bold",
+                                "italic",
+                                "ol",
+                                "ul",
+                                "link",
+                                "document-link",
+                                "image",
+                            ],
+                            label="Textový editor",
+                        ),
+                    ),
+                    (
+                        "gallery",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "gallery_items",
+                                    wagtail.core.blocks.ListBlock(
+                                        wagtail.images.blocks.ImageChooserBlock(
+                                            label="obrázek", required=True
+                                        ),
+                                        group="ostatní",
+                                        icon="image",
+                                        label="Galerie",
+                                    ),
+                                )
+                            ],
+                            label="Galerie",
+                        ),
+                    ),
+                ],
+                blank=True,
+                verbose_name="Článek",
+            ),
+        ),
+    ]
diff --git a/district/templates/district/base.html b/district/templates/district/base.html
index f043d6bb..ea83320f 100644
--- a/district/templates/district/base.html
+++ b/district/templates/district/base.html
@@ -17,6 +17,7 @@
 
   <!-- Styles -->
   <link rel="stylesheet" href="{% static "styleguide18/assets/css/styles.css" %}">
+  <link href="{% static "shared/vendor/fancybox/jquery.fancybox.min.css" %}" rel="stylesheet">
 
   <style type="text/css">
     .inline-block {
diff --git a/region/migrations/0026_alter_regionarticlepage_content.py b/region/migrations/0026_alter_regionarticlepage_content.py
new file mode 100644
index 00000000..f81ad070
--- /dev/null
+++ b/region/migrations/0026_alter_regionarticlepage_content.py
@@ -0,0 +1,63 @@
+# Generated by Django 4.0.3 on 2022-04-01 14:13
+
+import wagtail.core.blocks
+import wagtail.core.fields
+import wagtail.images.blocks
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("region", "0025_alter_regioncrossroadpage_content_and_more"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="regionarticlepage",
+            name="content",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "text",
+                        wagtail.core.blocks.RichTextBlock(
+                            features=[
+                                "h2",
+                                "h3",
+                                "h4",
+                                "bold",
+                                "italic",
+                                "ol",
+                                "ul",
+                                "link",
+                                "document-link",
+                                "image",
+                            ],
+                            label="Textový editor",
+                        ),
+                    ),
+                    (
+                        "gallery",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "gallery_items",
+                                    wagtail.core.blocks.ListBlock(
+                                        wagtail.images.blocks.ImageChooserBlock(
+                                            label="obrázek", required=True
+                                        ),
+                                        group="ostatní",
+                                        icon="image",
+                                        label="Galerie",
+                                    ),
+                                )
+                            ],
+                            label="Galerie",
+                        ),
+                    ),
+                ],
+                blank=True,
+                verbose_name="Článek",
+            ),
+        ),
+    ]
diff --git a/region/templates/region/base.html b/region/templates/region/base.html
index 0b20a02f..18eab8c0 100644
--- a/region/templates/region/base.html
+++ b/region/templates/region/base.html
@@ -17,6 +17,7 @@
 
   <!-- Styles -->
   <link rel="stylesheet" href="{% static "styleguide18/assets/css/styles.css" %}">
+  <link href="{% static "shared/vendor/fancybox/jquery.fancybox.min.css" %}" rel="stylesheet">
 
   <style type="text/css">
     .inline-block {
diff --git a/shared/blocks.py b/shared/blocks.py
index b0d28484..c4dbe9ae 100644
--- a/shared/blocks.py
+++ b/shared/blocks.py
@@ -1,6 +1,20 @@
 from django.forms.utils import ErrorList
 from wagtail.core import blocks
 from wagtail.core.blocks.struct_block import StructBlockValidationError
+from wagtail.images.blocks import ImageChooserBlock
+
+
+class GalleryBlock(blocks.StructBlock):
+    gallery_items = blocks.ListBlock(
+        ImageChooserBlock(label="obrázek", required=True),
+        label="Galerie",
+        icon="image",
+        group="ostatní",
+    )
+
+    class Meta:
+        label = "Galerie"
+        template = "styleguide/2.3.x/blocks/gallery_block.html"
 
 
 class MenuItemBlock(blocks.StructBlock):
diff --git a/shared/models.py b/shared/models.py
index d070cf93..6e847cac 100644
--- a/shared/models.py
+++ b/shared/models.py
@@ -6,7 +6,7 @@ from wagtail.core.fields import StreamField
 from wagtail.core.models import Page
 from wagtail.images.edit_handlers import ImageChooserPanel
 
-from shared.blocks import MenuItemBlock, MenuParentBlock
+from shared.blocks import GalleryBlock, MenuItemBlock, MenuParentBlock
 
 
 class SubpageMixin:
@@ -47,7 +47,13 @@ class ArticleMixin(models.Model):
     ### FIELDS
 
     content = StreamField(
-        [("text", RichTextBlock(label="Textový editor", features=RICH_TEXT_FEATURES))],
+        [
+            (
+                "text",
+                RichTextBlock(label="Textový editor", features=RICH_TEXT_FEATURES),
+            ),
+            ("gallery", GalleryBlock(label="Galerie")),
+        ],
         verbose_name="Článek",
         blank=True,
     )
diff --git a/shared/templates/styleguide/2.3.x/blocks/gallery_block.html b/shared/templates/styleguide/2.3.x/blocks/gallery_block.html
new file mode 100644
index 00000000..091b5efa
--- /dev/null
+++ b/shared/templates/styleguide/2.3.x/blocks/gallery_block.html
@@ -0,0 +1,10 @@
+{% load wagtailimages_tags %}
+<div class="content-block w-full px-4 my-6 grid grid-cols-4 gap-4">
+  {% for picture in self.gallery_items %}
+    {% image picture width-2000 as img %}
+    {% image picture fill-300x200 as thumb %}
+    <div>
+      <a data-fancybox="gallery" href="{{ img.url }}"><img data-src="{{ thumb.url }}" class="lazyload img-fluid" alt="{{ thumb.alt }}"></a>
+    </div>
+  {% endfor %}
+</div>
diff --git a/uniweb/migrations/0023_alter_uniwebarticlepage_content.py b/uniweb/migrations/0023_alter_uniwebarticlepage_content.py
new file mode 100644
index 00000000..5745f5a1
--- /dev/null
+++ b/uniweb/migrations/0023_alter_uniwebarticlepage_content.py
@@ -0,0 +1,63 @@
+# Generated by Django 4.0.3 on 2022-04-01 14:13
+
+import wagtail.core.blocks
+import wagtail.core.fields
+import wagtail.images.blocks
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("uniweb", "0022_remove_uniwebarticlepage_text_and_more"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="uniwebarticlepage",
+            name="content",
+            field=wagtail.core.fields.StreamField(
+                [
+                    (
+                        "text",
+                        wagtail.core.blocks.RichTextBlock(
+                            features=[
+                                "h2",
+                                "h3",
+                                "h4",
+                                "bold",
+                                "italic",
+                                "ol",
+                                "ul",
+                                "link",
+                                "document-link",
+                                "image",
+                            ],
+                            label="Textový editor",
+                        ),
+                    ),
+                    (
+                        "gallery",
+                        wagtail.core.blocks.StructBlock(
+                            [
+                                (
+                                    "gallery_items",
+                                    wagtail.core.blocks.ListBlock(
+                                        wagtail.images.blocks.ImageChooserBlock(
+                                            label="obrázek", required=True
+                                        ),
+                                        group="ostatní",
+                                        icon="image",
+                                        label="Galerie",
+                                    ),
+                                )
+                            ],
+                            label="Galerie",
+                        ),
+                    ),
+                ],
+                blank=True,
+                verbose_name="Článek",
+            ),
+        ),
+    ]
-- 
GitLab