Skip to content

Commit

Permalink
Merge pull request #14 from coderedcorp/12-feature-content-wall
Browse files Browse the repository at this point in the history
12 Feature Content Walls
  • Loading branch information
Cory Sutyak authored Aug 29, 2018
2 parents 3d090cc + d776148 commit 676895b
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 3 deletions.
17 changes: 17 additions & 0 deletions coderedcms/blocks/content_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,20 @@ class Meta:
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')
show_content_wall_on_children = blocks.BooleanBlock(
required=False,
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.')
)
class Meta:
icon = 'fa-stop'
label = _('Content Wall')
template = 'coderedcms/blocks/content_wall_block.html'
38 changes: 38 additions & 0 deletions coderedcms/migrations/0002_auto_20180829_1538.py

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions coderedcms/models/page_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from coderedcms.blocks import (
CONTENT_STREAMBLOCKS,
LAYOUT_STREAMBLOCKS,
ContentWallBlock,
OpenHoursBlock,
StructuredDataActionBlock)
from coderedcms.forms import CoderedFormBuilder, CoderedSubmissionsListView
Expand Down Expand Up @@ -275,6 +276,18 @@ class Meta:
)


###############
# Settings
###############

content_walls = StreamField(
[
('content_wall', ContentWallBlock())
],
blank=True,
verbose_name=_('Content Walls')
)

###############
# Search
###############
Expand Down Expand Up @@ -367,7 +380,12 @@ class Meta:
),
]

settings_panels = Page.settings_panels
settings_panels = (
Page.settings_panels +
[
StreamFieldPanel('content_walls'),
]
)

def __init__(self, *args, **kwargs):
"""
Expand Down Expand Up @@ -445,6 +463,21 @@ def get_index_children(self):

return super().get_children().live()

def get_content_walls(self, check_child_setting=True):
current_content_walls = []
if check_child_setting:
for wall in self.content_walls:
content_wall = wall.value
if wall.value['show_content_wall_on_children']:
current_content_walls.append(wall.value)
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.
Expand All @@ -462,7 +495,7 @@ def get_context(self, request, *args, **kwargs):

context['index_paginated'] = paged_children
context['index_children'] = all_children

context['content_walls'] = self.get_content_walls(check_child_setting=False)
return context


Expand Down
42 changes: 42 additions & 0 deletions coderedcms/models/snippet_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,48 @@ 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=_('Dismissible'),
)
show_once = models.BooleanField(
default=True,
verbose_name=_('Show once'),
help_text=_('Do not show the content wall to the same user again after it has been closed.')
)

panels = [
MultiFieldPanel(
[
FieldPanel('name'),
FieldPanel('is_dismissible'),
FieldPanel('show_once'),
],
heading=_('Content Wall')
),
StreamFieldPanel('content'),
]

def __str__(self):
return self.name


class CoderedEmail(ClusterableModel):
"""
General purpose abstract clusterable model used for holding email information.
Expand Down
11 changes: 11 additions & 0 deletions coderedcms/static/js/codered-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ $(document).ready(function()
$lightbox.find('img').attr('alt', orig_alt);
$lightbox.find('img').attr('title', orig_ttl);
});


/*** Content walls ***/
$(".modal[data-cr-wall-showonce='true']").on('hide.bs.modal', function() {
localStorage["cr_wall_" + $(this).data("cr-wall-id")] = "dismissed";
});
$(".modal[data-cr-wall-id]").each(function() {
if(localStorage["cr_wall_" + $(this).data("cr-wall-id")] === undefined) {
$(this).modal('show');
}
});
});
19 changes: 19 additions & 0 deletions coderedcms/templates/coderedcms/blocks/content_wall_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="modal fade content-wall {{self.settings.custom_css_class}}" tabindex="-1" role="dialog" data-cr-wall-id="{{self.content_wall.id}}"
{% if not self.content_wall.is_dismissible %} data-backdrop="static" data-keyboard="false" {% endif %}
{% if self.content_wall.show_once %} data-cr-wall-showonce="true" {% endif %}
{% if self.settings.custom_id %}id="{{self.settings.custom_id}}"{% endif %} >
<div class="modal-dialog modal-lg" 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>
8 changes: 8 additions & 0 deletions coderedcms/templates/coderedcms/pages/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
{% endblock %}
</div>

<div id="content-walls">
{% block content_walls %}
{% for content_wall in content_walls %}
{% include_block content_wall with settings=settings %}
{% endfor %}
{% endblock %}
</div>

{% block footer %}{% endblock %}

{% block required_scripts %}
Expand Down
1 change: 1 addition & 0 deletions coderedcms/templates/coderedcms/pages/web_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -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}});">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='coderedcms',
version='0.5.1',
version='0.6.0',
packages=find_packages(),
include_package_data=True,
license='BSD License',
Expand Down

0 comments on commit 676895b

Please sign in to comment.