2
0

blocks.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from django import forms
  2. from wagtail.blocks import (
  3. CharBlock,
  4. ChoiceBlock,
  5. FloatBlock,
  6. ListBlock,
  7. RichTextBlock,
  8. StreamBlock,
  9. StructBlock,
  10. )
  11. from wagtail.contrib.table_block.blocks import TableBlock
  12. from wagtail.contrib.typed_table_block.blocks import TypedTableBlock
  13. from wagtail.embeds.blocks import EmbedBlock
  14. from wagtail.images.blocks import ImageChooserBlock
  15. from bakerydemo.base.blocks import BlockQuote, HeadingBlock, ImageBlock
  16. class RecipeStepBlock(StructBlock):
  17. text = RichTextBlock(features=["bold", "italic", "link"])
  18. difficulty = ChoiceBlock(
  19. widget=forms.RadioSelect,
  20. choices=[("S", "Small"), ("M", "Medium"), ("L", "Large")],
  21. default="S",
  22. )
  23. class Meta:
  24. template = "blocks/recipe_step_block.html"
  25. icon = "tick"
  26. class RecipeStreamBlock(StreamBlock):
  27. """
  28. Define the custom blocks that `StreamField` will utilize
  29. """
  30. heading_block = HeadingBlock(group="Content")
  31. paragraph_block = RichTextBlock(
  32. icon="pilcrow", template="blocks/paragraph_block.html", group="Content"
  33. )
  34. block_quote = BlockQuote(group="Content")
  35. table_block = TableBlock(group="Content")
  36. typed_table_block = TypedTableBlock(
  37. [
  38. ("text", CharBlock()),
  39. ("numeric", FloatBlock()),
  40. ("rich_text", RichTextBlock()),
  41. ("image", ImageChooserBlock()),
  42. ],
  43. group="Content",
  44. )
  45. image_block = ImageBlock(group="Media")
  46. embed_block = EmbedBlock(
  47. help_text="Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
  48. icon="media",
  49. template="blocks/embed_block.html",
  50. group="Media",
  51. )
  52. ingredients_list = ListBlock(
  53. RichTextBlock(features=["bold", "italic", "link"]),
  54. min_num=2,
  55. max_num=10,
  56. icon="list-ol",
  57. group="Cooking",
  58. )
  59. steps_list = ListBlock(
  60. RecipeStepBlock(),
  61. min_num=2,
  62. max_num=10,
  63. icon="tasks",
  64. group="Cooking",
  65. )