layout_blocks.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. """
  2. Layout blocks are essentially a wrapper around content.
  3. e.g. rows, columns, hero units, etc.
  4. """
  5. from django.utils.translation import gettext_lazy as _
  6. from wagtail import blocks
  7. from wagtail.images.blocks import ImageChooserBlock
  8. from wagtailcrx.settings import crx_settings
  9. from .base_blocks import BaseLayoutBlock, CoderedAdvColumnSettings
  10. # Level 1 layout blocks
  11. class ColumnBlock(BaseLayoutBlock):
  12. """
  13. Renders content in a column.
  14. """
  15. column_size = blocks.ChoiceBlock(
  16. choices=crx_settings.CRX_FRONTEND_COL_SIZE_CHOICES,
  17. default=crx_settings.CRX_FRONTEND_COL_SIZE_DEFAULT,
  18. required=False,
  19. label=_('Column size'),
  20. )
  21. advsettings_class = CoderedAdvColumnSettings
  22. class Meta:
  23. template = 'wagtailcrx/blocks/column_block.html'
  24. icon = 'placeholder'
  25. label = 'Column'
  26. class GridBlock(BaseLayoutBlock):
  27. """
  28. Renders a row of columns.
  29. """
  30. fluid = blocks.BooleanBlock(
  31. required=False,
  32. label=_('Full width'),
  33. )
  34. class Meta:
  35. template = 'wagtailcrx/blocks/grid_block.html'
  36. icon = 'cr-columns'
  37. label = _('Responsive Grid Row')
  38. def __init__(self, local_blocks=None, **kwargs):
  39. super().__init__(
  40. local_blocks=[
  41. ('content', ColumnBlock(local_blocks))
  42. ]
  43. )
  44. class CardGridBlock(BaseLayoutBlock):
  45. """
  46. Renders a row of cards.
  47. """
  48. fluid = blocks.BooleanBlock(
  49. required=False,
  50. label=_('Full width'),
  51. )
  52. class Meta:
  53. template = 'wagtailcrx/blocks/cardgrid_deck.html'
  54. icon = 'cr-th-large'
  55. label = _('Card Grid')
  56. class HeroBlock(BaseLayoutBlock):
  57. """
  58. Wrapper with color and image background options.
  59. """
  60. fluid = blocks.BooleanBlock(
  61. required=False,
  62. default=True,
  63. label=_('Full width'),
  64. )
  65. is_parallax = blocks.BooleanBlock(
  66. required=False,
  67. label=_('Parallax Effect'),
  68. help_text=_(
  69. 'Background images scroll slower than foreground images, creating an illusion of depth.'), # noqa
  70. )
  71. background_image = ImageChooserBlock(required=False)
  72. tile_image = blocks.BooleanBlock(
  73. required=False,
  74. default=False,
  75. label=_('Tile background image'),
  76. )
  77. background_color = blocks.CharBlock(
  78. required=False,
  79. max_length=255,
  80. label=_('Background color'),
  81. help_text=_('Hexadecimal, rgba, or CSS color notation (e.g. #ff0011)'),
  82. )
  83. foreground_color = blocks.CharBlock(
  84. required=False,
  85. max_length=255,
  86. label=_('Text color'),
  87. help_text=_('Hexadecimal, rgba, or CSS color notation (e.g. #ff0011)'),
  88. )
  89. class Meta:
  90. template = 'wagtailcrx/blocks/hero_block.html'
  91. icon = 'cr-newspaper-o'
  92. label = 'Hero Unit'