Browse Source

Added content walls.

Cory Sutyak 6 years ago
parent
commit
d2a90c049b

+ 12 - 0
coderedcms/blocks/content_blocks.py

@@ -295,3 +295,15 @@ class PriceListBlock(BaseBlock):
         template = 'coderedcms/blocks/pricelist_block.html'
         icon = 'fa-usd'
         label = _('Price List')
+
+
+class ContentWallBlock(BaseBlock):
+    """
+    Enables choosing a ContentWall snippet.
+    """
+    content_wall = SnippetChooserBlock('coderedcms.ContentWall')
+
+    class Meta:
+        icon = 'fa-stop'
+        label = _('Content Wall')
+        template = 'coderedcms/blocks/content_wall_block.html'

File diff suppressed because it is too large
+ 24 - 0
coderedcms/migrations/0002_auto_20180823_1106.py


+ 44 - 2
coderedcms/models/page_models.py

@@ -39,6 +39,7 @@ from coderedcms import schema, utils
 from coderedcms.blocks import (
     CONTENT_STREAMBLOCKS,
     LAYOUT_STREAMBLOCKS,
+    ContentWallBlock,
     OpenHoursBlock,
     StructuredDataActionBlock)
 from coderedcms.forms import CoderedFormBuilder, CoderedSubmissionsListView
@@ -275,6 +276,23 @@ class CoderedPage(Page, metaclass=CoderedPageMeta):
     )
 
 
+    ###############
+    # Settings
+    ###############
+
+    content_walls = StreamField(
+        [
+            ('content_wall', ContentWallBlock())
+        ],
+        blank=True,
+        verbose_name=_('Content Walls')
+    )
+    show_content_wall_on_children = models.BooleanField(
+        default=False,
+        verbose_name=_('Show content walls on children pages?'),
+        help_text=_('If this is checked, the content walls will be displayed on all children pages of this page.')
+    )
+
     ###############
     # Search
     ###############
@@ -367,7 +385,19 @@ class CoderedPage(Page, metaclass=CoderedPageMeta):
         ),
     ]
 
-    settings_panels = Page.settings_panels
+    settings_panels = (
+        Page.settings_panels + 
+        [
+            MultiFieldPanel(
+                [
+                    StreamFieldPanel('content_walls'),
+                    FieldPanel('show_content_wall_on_children'),
+                ],
+                heading=_('Content Wall Settings'),
+            )
+
+        ]
+    )
 
     def __init__(self, *args, **kwargs):
         """
@@ -445,6 +475,18 @@ class CoderedPage(Page, metaclass=CoderedPageMeta):
 
         return super().get_children().live()
 
+    def get_content_walls(self, check_child_setting=True):
+        current_content_walls = []
+
+        if check_child_setting:
+            current_content_walls = self.content_walls if self.show_content_wall_on_children else []
+        else:
+            current_content_walls = self.content_walls
+        try:
+            return list(current_content_walls) + self.get_parent().specific.get_content_walls()
+        except AttributeError:
+            return list(current_content_walls)
+
     def get_context(self, request, *args, **kwargs):
         """
         Add child pages and paginated child pages to context.
@@ -462,7 +504,7 @@ class CoderedPage(Page, metaclass=CoderedPageMeta):
 
             context['index_paginated'] = paged_children
             context['index_children'] = all_children
-
+        context['content_walls'] = self.get_content_walls(check_child_setting=False)
         return context
 
 

+ 29 - 0
coderedcms/models/snippet_models.py

@@ -211,7 +211,36 @@ class Footer(models.Model):
     def __str__(self):
         return self.name
 
+@register_snippet
+class ContentWall(models.Model):
+    """
+    Snippet that restricts access to a page with a modal.
+    """
+    class Meta:
+        verbose_name = _('Content Wall')
 
+    name = models.CharField(
+        max_length=255,
+        verbose_name=_('Name'),
+    )
+    content = StreamField(
+        LAYOUT_STREAMBLOCKS,
+        verbose_name=_('Content'),
+    )
+    is_dismissible = models.BooleanField(
+        default=True,
+        verbose_name=_('Is Dismissible')
+    )
+
+    panels = [
+        FieldPanel('name'),
+        StreamFieldPanel('content'),
+        FieldPanel('is_dismissible'),
+    ]
+
+    def __str__(self):
+        return self.name
+        
 class CoderedEmail(ClusterableModel):
     """
     General purpose abstract clusterable model used for holding email information.

+ 3 - 0
coderedcms/static/js/codered-front.js

@@ -100,4 +100,7 @@ $(document).ready(function()
         $lightbox.find('img').attr('alt', orig_alt);
         $lightbox.find('img').attr('title', orig_ttl);
     });
+
+    /*** Content Walls ***/
+    $('.content-wall').modal('show')
 });

+ 23 - 0
coderedcms/templates/coderedcms/blocks/content_wall_block.html

@@ -0,0 +1,23 @@
+{% extends "coderedcms/blocks/base_block.html" %}
+
+{% block block_render %}
+
+<div class="modal content-wall" tabindex="-1" role="dialog">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            {% if self.content_wall.is_dismissible %}
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            {% endif %}
+            <div class="modal-body">
+                {{self.content_wall.content}}
+            </div>
+        </div>
+    </div>
+</div>
+
+{% endblock %}
+

+ 8 - 0
coderedcms/templates/coderedcms/pages/base.html

@@ -103,6 +103,14 @@
             {% endblock %}
         </div>
 
+        <div id="content-walls">
+            {% block content_walls %}
+                {% for content_wall in content_walls %}
+                        {{content_wall}}
+                {% endfor %}
+            {% endblock %}
+        </div>
+
         {% block footer %}{% endblock %}
 
         {% block required_scripts %}

+ 1 - 0
coderedcms/templates/coderedcms/pages/web_page.html

@@ -2,6 +2,7 @@
 {% load wagtailcore_tags wagtailimages_tags %}
 
 {% block content %}
+
   {% if self.cover_image %}
     {% image page.cover_image fill-2000x1000 as cover_image %}
     <div class="hero-bg mb-5" style="background-image:url({{cover_image.url}});">

Some files were not shown because too many files changed in this diff