blocks.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from wagtail.wagtailimages.blocks import ImageChooserBlock
  2. from wagtail.wagtailembeds.blocks import EmbedBlock
  3. from wagtail.wagtailcore.blocks import (
  4. CharBlock, ChoiceBlock, RichTextBlock, StreamBlock, StructBlock, TextBlock,
  5. )
  6. class ImageBlock(StructBlock):
  7. image = ImageChooserBlock(required=True)
  8. caption = CharBlock(required=False)
  9. attribution = CharBlock(required=False)
  10. class Meta:
  11. icon = 'image'
  12. template = "blocks/image_block.html"
  13. class HeadingBlock(StructBlock):
  14. heading_text = CharBlock(classname="title", required=True)
  15. size = ChoiceBlock(choices=[
  16. ('', 'Select a header size'),
  17. ('h2', 'H2'),
  18. ('h3', 'H3'),
  19. ('h4', 'H4')
  20. ], blank=True, required=False)
  21. class Meta:
  22. icon = "title"
  23. template = "blocks/heading_block.html"
  24. class BlockQuote(StructBlock):
  25. text = TextBlock(),
  26. attribute_name = CharBlock(
  27. blank=True, required=False, label='e.g. Guy Picciotto')
  28. class Meta:
  29. icon = "fa-quote-left"
  30. template = "blocks/blockquote.html"
  31. # StreamBlocks
  32. class BaseStreamBlock(StreamBlock):
  33. heading_block = HeadingBlock()
  34. paragraph_block = RichTextBlock(
  35. icon="fa-paragraph",
  36. template="blocks/paragraph_block.html"
  37. )
  38. image_block = ImageBlock()
  39. block_quote = BlockQuote()
  40. embed_block = EmbedBlock(
  41. help_text='Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks',
  42. icon="fa-s15",
  43. template="blocks/embed_block.html")