123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- """
- Content blocks are for building complex, nested HTML structures that usually
- contain sub-blocks, and may require javascript to function properly.
- """
- from django.utils.translation import gettext_lazy as _
- from wagtail import blocks
- from wagtail.documents.blocks import DocumentChooserBlock
- from wagtail.images.blocks import ImageChooserBlock
- from wagtail.snippets.blocks import SnippetChooserBlock
- from .base_blocks import BaseBlock, BaseLayoutBlock, ButtonMixin, CollectionChooserBlock
- from .html_blocks import ButtonBlock
- class CardBlock(BaseBlock):
- """
- A component of information with image, text, and buttons.
- """
- image = ImageChooserBlock(
- required=False,
- max_length=255,
- label=_('Image'),
- )
- title = blocks.CharBlock(
- required=False,
- max_length=255,
- label=_('Title'),
- )
- subtitle = blocks.CharBlock(
- required=False,
- max_length=255,
- label=_('Subtitle'),
- )
- description = blocks.RichTextBlock(
- features=['bold', 'italic', 'ol', 'ul', 'hr', 'link', 'document-link'],
- label=_('Body'),
- )
- links = blocks.StreamBlock(
- [('Links', ButtonBlock())],
- blank=True,
- required=False,
- label=_('Links'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/card_foot.html'
- icon = 'cr-list-alt'
- label = _('Card')
- class CarouselBlock(BaseBlock):
- """
- Enables choosing a Carousel snippet.
- """
- carousel = SnippetChooserBlock('wagtailcrx.Carousel')
- class Meta:
- icon = 'image'
- label = _('Carousel')
- template = 'wagtailcrx/blocks/carousel_block.html'
- class ImageGalleryBlock(BaseBlock):
- """
- Show a collection of images with interactive previews that expand to
- full size images in a modal.
- """
- collection = CollectionChooserBlock(
- required=True,
- label=_('Image Collection'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/image_gallery_block.html'
- icon = 'image'
- label = _('Image Gallery')
- class ModalBlock(ButtonMixin, BaseLayoutBlock):
- """
- Renders a button that then opens a popup/modal with content.
- """
- header = blocks.CharBlock(
- required=False,
- max_length=255,
- label=_('Modal heading'),
- )
- content = blocks.StreamBlock(
- [],
- label=_('Modal content'),
- )
- footer = blocks.StreamBlock(
- [
- ('text', blocks.CharBlock(icon='cr-font', max_length=255, label=_('Simple Text'))), # noqa
- ('button', ButtonBlock()),
- ],
- required=False,
- label=_('Modal footer'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/modal_block.html'
- icon = 'cr-window-maximize'
- label = _('Modal')
- class NavBaseLinkBlock(BaseBlock):
- display_text = blocks.CharBlock(
- required=False,
- max_length=255,
- label=_('Display text'),
- )
- image = ImageChooserBlock(
- required=False,
- label=_('Image'),
- )
- class NavExternalLinkBlock(NavBaseLinkBlock):
- """
- External link.
- """
- link = blocks.CharBlock(
- required=False,
- label=_('URL'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/external_link_block.html'
- label = _('External Link')
- class NavPageLinkBlock(NavBaseLinkBlock):
- """
- Page link.
- """
- page = blocks.PageChooserBlock(
- label=_('Page'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/page_link_block.html'
- label = _('Page Link')
- class NavDocumentLinkBlock(NavBaseLinkBlock):
- """
- Document link.
- """
- document = DocumentChooserBlock(
- label=_('Document'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/document_link_block.html'
- label = _('Document Link')
- class NavSubLinkBlock(BaseBlock):
- """
- Streamblock for rendering nested sub-links.
- """
- sub_links = blocks.StreamBlock(
- [
- ('page_link', NavPageLinkBlock()),
- ('external_link', NavExternalLinkBlock()),
- ('document_link', NavDocumentLinkBlock()),
- ],
- required=False,
- label=_('Sub-links'),
- )
- class NavExternalLinkWithSubLinkBlock(NavSubLinkBlock, NavExternalLinkBlock):
- """
- Extermal link with option for sub-links.
- """
- class Meta:
- label = _('External link with sub-links')
- class NavPageLinkWithSubLinkBlock(NavSubLinkBlock, NavPageLinkBlock):
- """
- Page link with option for sub-links or showing child pages.
- """
- show_child_links = blocks.BooleanBlock(
- required=False,
- default=False,
- label=_('Show child pages'),
- help_text=_('Automatically show a link to the Page’s child pages as a dropdown menu.'),
- )
- class Meta:
- label = _('Page link with sub-links')
- class NavDocumentLinkWithSubLinkBlock(NavSubLinkBlock, NavDocumentLinkBlock):
- """
- Document link with option for sub-links.
- """
- class Meta:
- label = _('Document link with sub-links')
- class PriceListItemBlock(BaseBlock):
- """
- Represents one item in a PriceListBlock, such as an entree in a restaurant menu.
- """
- image = ImageChooserBlock(
- required=False,
- label=_('Image'),
- )
- name = blocks.CharBlock(
- required=True,
- max_length=255,
- label=_('Name'),
- )
- description = blocks.TextBlock(
- required=False,
- rows=4,
- label=_('Description'),
- )
- price = blocks.CharBlock(
- required=True,
- label=_('Price'),
- help_text=_('Any text here. Include currency sign if desired.'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/pricelistitem_block.html'
- icon = 'cr-usd'
- label = _('Price List Item')
- class PriceListBlock(BaseBlock):
- """
- A price list, such as a menu for a restaurant.
- """
- heading = blocks.CharBlock(
- required=False,
- max_length=255,
- label=_('Heading'),
- )
- items = blocks.StreamBlock(
- [
- ('item', PriceListItemBlock()),
- ],
- label=_('Items'),
- )
- class Meta:
- template = 'wagtailcrx/blocks/pricelist_block.html'
- icon = 'cr-usd'
- label = _('Price List')
- class ContentWallBlock(BaseBlock):
- """
- Enables choosing a ContentWall snippet.
- """
- content_wall = SnippetChooserBlock('wagtailcrx.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.') # noqa
- )
- class Meta:
- icon = 'cr-stop'
- label = _('Content Wall')
- template = 'wagtailcrx/blocks/content_wall_block.html'
- class ReusableContentBlock(BaseBlock):
- """
- Enables choosing a ResusableContent snippet.
- """
- content = SnippetChooserBlock('wagtailcrx.ReusableContent')
- class Meta:
- icon = 'cr-recycle'
- label = _('Reusable Content')
- template = 'wagtailcrx/blocks/reusable_content_block.html'
|