blocks.py 1.5 KB

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