You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2020/05/04 15:42:46 UTC

[airavata-django-portal] 02/05: AIRAVATA-3306 Allow specifying container for rows

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit a27cfb8c399b793550e755b445317fc89ea03ac2
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon May 4 10:33:07 2020 -0400

    AIRAVATA-3306 Allow specifying container for rows
---
 .../templates/blocks/bootstrap/container.html      | 13 ++++++
 .../django_airavata_wagtail_base/blank_page.html   | 19 ++++++---
 django_airavata/wagtailapps/base/blocks.py         | 46 ++++++++++++++++++++++
 .../0023_rowblankpagerelation_container.py         | 23 +++++++++++
 django_airavata/wagtailapps/base/models.py         | 24 ++++++++++-
 5 files changed, 117 insertions(+), 8 deletions(-)

diff --git a/django_airavata/templates/blocks/bootstrap/container.html b/django_airavata/templates/blocks/bootstrap/container.html
new file mode 100644
index 0000000..419f717
--- /dev/null
+++ b/django_airavata/templates/blocks/bootstrap/container.html
@@ -0,0 +1,13 @@
+{% load wagtailimages_tags %}
+
+<!-- close previous container -->
+</div>
+<!-- close previous container wrapper -->
+</div>
+<div class="container-wrapper {{ value.custom_classes }}" style="{{ value.inline_styles }}
+{% if value.background_image %}
+{% image self.background_image original as background_image_orig %}
+background-image: url({{ background_image_orig.url }});
+{% endif %}
+">
+<div class="{{ container_class }}">
diff --git a/django_airavata/templates/django_airavata_wagtail_base/blank_page.html b/django_airavata/templates/django_airavata_wagtail_base/blank_page.html
index 1f7347c..8e672db 100644
--- a/django_airavata/templates/django_airavata_wagtail_base/blank_page.html
+++ b/django_airavata/templates/django_airavata_wagtail_base/blank_page.html
@@ -24,14 +24,21 @@
   {% get_announcements %}
 {% endif %}
 
-<div class="container-fluid">
-  {% for item in page.row.all %}
-  <div class="row">
-    {% for block in item.body %}
-      {% include_block block.value %}
+<div class="container-fluid-wrapper">
+  <div class="container-fluid">
+    {% for item in page.row.all %}
+      {% if item.container %}
+        {% comment %} There can only be one container. This will close the previous
+        container and start a new one. {% endcomment %}
+        {% include_block item.container|first %}
+      {% endif %}
+    <div class="row">
+      {% for block in item.body %}
+        {% include_block block.value %}
+      {% endfor %}
+    </div>
     {% endfor %}
   </div>
-  {% endfor %}
 </div>
 
 {% if page.show_footer == "yes" %}
diff --git a/django_airavata/wagtailapps/base/blocks.py b/django_airavata/wagtailapps/base/blocks.py
index 56cd97d..bbb8a6d 100644
--- a/django_airavata/wagtailapps/base/blocks.py
+++ b/django_airavata/wagtailapps/base/blocks.py
@@ -486,6 +486,52 @@ class CssStreamBlock(StreamBlock):
     css_comment = CssCommentBlock()
 
 
+class ContainerBlock(StructBlock):
+    inline_styles = TextBlock(
+        required=False,
+        blank=True,
+        help_text="Apply inline CSS styles to container wrapper.")
+    custom_classes = CharBlock(
+        required=False,
+        help_text="Apply custom CSS classes to container wrapper. You can "
+                  "define CSS classes in a Custom CSS snippet.")
+    background_image = ImageChooserBlock(
+        required=False,
+        help_text="Apply background image to container wrapper.")
+
+    def get_context(self, value, parent_context=None):
+        context = super().get_context(value, parent_context=parent_context)
+        context['container_class'] = self.container_class
+        return context
+
+    class Meta:
+        abstract = True
+        template = "blocks/bootstrap/container.html"
+
+
+class FullWidthContainer(ContainerBlock):
+    container_class = "container-fluid"
+
+    class Meta:
+        icon = "fa-arrows-h"
+
+
+class MaxWidthContainer(ContainerBlock):
+    container_class = "container"
+
+    class Meta:
+        icon = "fa-square-o"
+
+
+class ContainerChoiceBlock(StreamBlock):
+    full_width_container = FullWidthContainer()
+    max_width_container = MaxWidthContainer()
+
+    class Meta:
+        max_num = 1
+        required = False
+
+
 class NavItem(StructBlock):
     link = CharBlock(help_text="Full URL or relative path (e.g., /auth/login)")
     link_text = CharBlock(required=False)
diff --git a/django_airavata/wagtailapps/base/migrations/0023_rowblankpagerelation_container.py b/django_airavata/wagtailapps/base/migrations/0023_rowblankpagerelation_container.py
new file mode 100644
index 0000000..6245de8
--- /dev/null
+++ b/django_airavata/wagtailapps/base/migrations/0023_rowblankpagerelation_container.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.28 on 2020-05-04 14:30
+from __future__ import unicode_literals
+
+from django.db import migrations
+import wagtail.core.blocks
+import wagtail.core.fields
+import wagtail.images.blocks
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('django_airavata_wagtail_base', '0022_auto_20191106_1542'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='rowblankpagerelation',
+            name='container',
+            field=wagtail.core.fields.StreamField((('full_width_container', wagtail.core.blocks.StructBlock((('inline_styles', wagtail.core.blocks.TextBlock(blank=True, help_text='Apply inline CSS styles to container wrapper.', required=False)), ('custom_classes', wagtail.core.blocks.CharBlock(help_text='Apply custom CSS classes to container wrapper. You can define CSS classes in a Custom CSS snippet.', required=False)), ('background_image', wagtail.images.blocks.ImageChooserBlock(help_t [...]
+        ),
+    ]
diff --git a/django_airavata/wagtailapps/base/models.py b/django_airavata/wagtailapps/base/models.py
index 4a85e1b..01b3980 100644
--- a/django_airavata/wagtailapps/base/models.py
+++ b/django_airavata/wagtailapps/base/models.py
@@ -19,7 +19,7 @@ from wagtail.core.models import Orderable, Page
 from wagtail.images.edit_handlers import ImageChooserPanel
 from wagtail.snippets.models import register_snippet
 
-from .blocks import BaseStreamBlock, CssStreamBlock, Nav
+from .blocks import BaseStreamBlock, ContainerChoiceBlock, CssStreamBlock, Nav
 
 
 @register_snippet
@@ -685,7 +685,27 @@ class Row(models.Model):
         abstract = True
 
 
-class RowBlankPageRelation(Orderable, Row):
+class BootstrapRow(Row):
+    container = StreamField(
+        ContainerChoiceBlock(),
+        null=True,
+        blank=True,
+        help_text="(Optional) Create a new Bootstrap container for this "
+                  "and following rows.")
+    body = StreamField(
+        BaseStreamBlock(), verbose_name="Row Content", blank=True, null=True
+    )
+
+    panels = [
+        StreamFieldPanel('container'),
+        StreamFieldPanel('body'),
+    ]
+
+    class Meta:
+        abstract = True
+
+
+class RowBlankPageRelation(Orderable, BootstrapRow):
     page = ParentalKey('django_airavata_wagtail_base.BlankPage',
                        on_delete=models.CASCADE, related_name='row')