Skip to content

Commit

Permalink
10 Feature Reusable Content Snippet (#13)
Browse files Browse the repository at this point in the history
Implementing #10 reusable content snippet.
  • Loading branch information
Cory Sutyak authored and vsalvino committed Sep 12, 2018
1 parent 676895b commit b1406a0
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 1 deletion.
1 change: 1 addition & 0 deletions coderedcms/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
('page_list', PageListBlock()),
('modal', ModalBlock(HTML_STREAMBLOCKS)),
('pricelist', PriceListBlock()),
('reusable_content', ReusableContentBlock()),
]

NAVIGATION_STREAMBLOCKS = [
Expand Down
12 changes: 12 additions & 0 deletions coderedcms/blocks/content_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,15 @@ class Meta:
icon = 'fa-stop'
label = _('Content Wall')
template = 'coderedcms/blocks/content_wall_block.html'


class ReusableContentBlock(BaseBlock):
"""
Enables choosing a ResusableContent snippet.
"""
content = SnippetChooserBlock('coderedcms.ReusableContent')

class Meta:
icon = 'fa-recycle'
label = _('Reusable Content')
template = 'coderedcms/blocks/reusable_content_block.html'
42 changes: 42 additions & 0 deletions coderedcms/migrations/0003_auto_20180912_1632.py

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions coderedcms/models/snippet_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,74 @@ class Meta:
def __str__(self):
return self.name

@register_snippet
class ReusableContent(models.Model):
"""
Snippet for resusable content in streamfields.
"""
class Meta:
verbose_name = _('Reusable Content')
verbose_name_plural = _('Reusable Content')

name = models.CharField(
max_length=255,
verbose_name=_('Name'),
)
content = StreamField(
LAYOUT_STREAMBLOCKS,
verbose_name=_('content')
)

panels = [
FieldPanel('name'),
StreamFieldPanel('content')
]

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


@register_snippet
class ContentWall(models.Model):
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load wagtailcore_tags %}
{% include_block self.content.content %}
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.6.0',
version='0.7.0',
packages=find_packages(),
include_package_data=True,
license='BSD License',
Expand Down

0 comments on commit b1406a0

Please sign in to comment.