layout_blocks.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 coderedcms.settings import crx_settings
  9. from .base_blocks import BaseLayoutBlock
  10. from .base_blocks import CoderedAdvColumnSettings
  11. # Level 1 layout blocks
  12. class ColumnBlock(BaseLayoutBlock):
  13. """
  14. Renders content in a column.
  15. """
  16. column_size = blocks.ChoiceBlock(
  17. choices=crx_settings.CRX_FRONTEND_COL_SIZE_CHOICES,
  18. default=crx_settings.CRX_FRONTEND_COL_SIZE_DEFAULT,
  19. required=False,
  20. label=_("Column size"),
  21. )
  22. advsettings_class = CoderedAdvColumnSettings
  23. class Meta:
  24. template = "coderedcms/blocks/column_block.html"
  25. icon = "placeholder"
  26. label = "Column"
  27. preview_template = "wagtailcore/shared/block_preview.html"
  28. description = "Renders the content in a column."
  29. preview_value = (
  30. {
  31. "settings": {
  32. "custom_template": "",
  33. },
  34. "content": [("text", "<h1>This is a column!</h1>")],
  35. },
  36. )
  37. class GridBlock(BaseLayoutBlock):
  38. """
  39. Renders a row of columns.
  40. """
  41. fluid = blocks.BooleanBlock(
  42. required=False,
  43. label=_("Full width"),
  44. )
  45. class Meta:
  46. template = "coderedcms/blocks/grid_block.html"
  47. icon = "cr-columns"
  48. label = _("Responsive Grid Row")
  49. preview_template = "wagtailcore/shared/block_preview.html"
  50. description = "Renders a row of columns."
  51. preview_value = {
  52. "settings": {
  53. "custom_template": "",
  54. },
  55. "content": [
  56. (
  57. "content",
  58. {
  59. "settings": {
  60. "custom_template": "",
  61. },
  62. "content": [("text", "<h1>This is a row block!</h1>")],
  63. },
  64. ),
  65. (
  66. "content",
  67. {
  68. "settings": {
  69. "custom_template": "",
  70. },
  71. "content": [("text", "<h1>With Two Columns!</h1>")],
  72. },
  73. ),
  74. ],
  75. }
  76. def __init__(self, local_blocks=None, **kwargs):
  77. super().__init__(local_blocks=[("content", ColumnBlock(local_blocks))])
  78. class CardGridBlock(BaseLayoutBlock):
  79. """
  80. Renders a row of cards.
  81. """
  82. fluid = blocks.BooleanBlock(
  83. required=False,
  84. label=_("Full width"),
  85. )
  86. class Meta:
  87. template = "coderedcms/blocks/cardgrid_deck.html"
  88. icon = "cr-th-large"
  89. label = _("Card Grid")
  90. class HeroBlock(BaseLayoutBlock):
  91. """
  92. Wrapper with color and image background options.
  93. """
  94. fluid = blocks.BooleanBlock(
  95. required=False,
  96. default=True,
  97. label=_("Full width"),
  98. )
  99. is_parallax = blocks.BooleanBlock(
  100. required=False,
  101. label=_("Parallax Effect"),
  102. help_text=_(
  103. "Background images scroll slower than foreground images, creating an illusion of depth."
  104. ),
  105. )
  106. background_image = ImageChooserBlock(required=False)
  107. tile_image = blocks.BooleanBlock(
  108. required=False,
  109. default=False,
  110. label=_("Tile background image"),
  111. )
  112. background_color = blocks.CharBlock(
  113. required=False,
  114. max_length=255,
  115. label=_("Background color"),
  116. help_text=_("Hexadecimal, rgba, or CSS color notation (e.g. #ff0011)"),
  117. )
  118. foreground_color = blocks.CharBlock(
  119. required=False,
  120. max_length=255,
  121. label=_("Text color"),
  122. help_text=_("Hexadecimal, rgba, or CSS color notation (e.g. #ff0011)"),
  123. )
  124. class Meta:
  125. template = "coderedcms/blocks/hero_block.html"
  126. icon = "cr-newspaper-o"
  127. label = "Hero Unit"
  128. preview_value = {
  129. "settings": {
  130. "custom_template": "",
  131. },
  132. "background_color": "#ff0011",
  133. "foreground_color": "#ffffff",
  134. "content": [
  135. (
  136. "row",
  137. {
  138. "settings": {
  139. "custom_template": "",
  140. },
  141. "content": [
  142. (
  143. "content",
  144. {
  145. "settings": {
  146. "custom_template": "",
  147. },
  148. "content": [
  149. ("text", "<h1>This is a hero block!")
  150. ],
  151. },
  152. )
  153. ],
  154. },
  155. )
  156. ],
  157. }
  158. preview_template = "wagtailcore/shared/block_preview.html"
  159. description = "Wrapper with color and image background options."