-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathblocks.py
38 lines (25 loc) · 1020 Bytes
/
blocks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock
class ImageBlock(blocks.StructBlock):
image = ImageChooserBlock()
caption = blocks.CharBlock(required=False)
class Meta: # type: ignore
template = "blocks/image_block.html"
def is_rendering_newsletter(context):
return bool((context or {}).get("rendering_newsletter"))
class WebOnlyBlock(blocks.RichTextBlock):
def render(self, value, context=None):
if is_rendering_newsletter(context):
return ""
return super().render(value, context)
class EmailOnlyBlock(blocks.RichTextBlock):
def render(self, value, context=None):
if not is_rendering_newsletter(context):
return ""
return super().render(value, context)
class StoryBlock(blocks.StreamBlock):
rich_text = blocks.RichTextBlock()
image = ImageBlock()
raw_html = blocks.RawHTMLBlock()
email_only = EmailOnlyBlock(group="Channel")
web_only = WebOnlyBlock(group="Channel")