layout_blocks.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 ugettext_lazy as _
  6. from wagtail.core import blocks
  7. from wagtail.images.blocks import ImageChooserBlock
  8. from coderedcms.settings import cr_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=cr_settings['FRONTEND_COL_SIZE_CHOICES'],
  17. default=cr_settings['FRONTEND_COL_SIZE_DEFAULT'],
  18. required=False,
  19. label=_('Column size'),
  20. )
  21. advsettings_class = CoderedAdvColumnSettings
  22. class Meta:
  23. template = 'coderedcms/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 = 'coderedcms/blocks/grid_block.html'
  36. icon = 'fa-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 = 'coderedcms/blocks/cardgrid_deck.html'
  54. icon = 'fa-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=_('Background images scroll slower than foreground images, creating an illusion of depth.'),
  69. )
  70. background_image = ImageChooserBlock(required=False)
  71. tile_image = blocks.BooleanBlock(
  72. required=False,
  73. default=False,
  74. label=_('Tile background image'),
  75. )
  76. background_color = blocks.CharBlock(
  77. required=False,
  78. max_length=255,
  79. label=_('Background color'),
  80. help_text=_('Hexadecimal, rgba, or CSS color notation (e.g. #ff0011)'),
  81. )
  82. foreground_color = blocks.CharBlock(
  83. required=False,
  84. max_length=255,
  85. label=_('Text color'),
  86. help_text=_('Hexadecimal, rgba, or CSS color notation (e.g. #ff0011)'),
  87. )
  88. class Meta:
  89. template = 'coderedcms/blocks/hero_block.html'
  90. icon = 'fa-newspaper-o'
  91. label = 'Hero Unit'