stream_form_blocks.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. from django.utils.translation import gettext_lazy as _
  2. from wagtail import blocks
  3. from wagtailcrx.wagtail_flexible_forms import blocks as form_blocks
  4. from wagtailcrx.blocks.base_blocks import BaseBlock, CoderedAdvSettings
  5. from wagtailcrx.forms import (
  6. CoderedDateField, CoderedDateInput,
  7. CoderedDateTimeField, CoderedDateTimeInput,
  8. CoderedTimeField, CoderedTimeInput,
  9. SecureFileField
  10. )
  11. class CoderedFormAdvSettings(CoderedAdvSettings):
  12. condition_trigger_id = blocks.CharBlock(
  13. required=False,
  14. max_length=255,
  15. label=_('Condition Trigger ID'),
  16. help_text=_(
  17. 'The "Custom ID" of another field that that will trigger this field to be shown/hidden.') # noqa
  18. )
  19. condition_trigger_value = blocks.CharBlock(
  20. required=False,
  21. max_length=255,
  22. label=_('Condition Trigger Value'),
  23. help_text=_(
  24. 'The value of the field in "Condition Trigger ID" that will trigger this field to be shown.') # noqa
  25. )
  26. class FormBlockMixin(BaseBlock):
  27. class Meta:
  28. abstract = True
  29. advsettings_class = CoderedFormAdvSettings
  30. class CoderedStreamFormFieldBlock(form_blocks.OptionalFormFieldBlock, FormBlockMixin):
  31. pass
  32. class CoderedStreamFormCharFieldBlock(form_blocks.CharFieldBlock, FormBlockMixin):
  33. class Meta:
  34. label = _("Text or Email input")
  35. icon = "cr-window-minimize"
  36. class CoderedStreamFormTextFieldBlock(form_blocks.TextFieldBlock, FormBlockMixin):
  37. class Meta:
  38. label = _("Multi-line text")
  39. icon = "cr-align-left"
  40. class CoderedStreamFormNumberFieldBlock(form_blocks.NumberFieldBlock, FormBlockMixin):
  41. class Meta:
  42. label = _("Numbers only")
  43. icon = "cr-hashtag"
  44. class CoderedStreamFormCheckboxFieldBlock(form_blocks.CheckboxFieldBlock, FormBlockMixin):
  45. class Meta:
  46. label = _("Single Checkbox")
  47. icon = "cr-check-square-o"
  48. class CoderedStreamFormRadioButtonsFieldBlock(form_blocks.RadioButtonsFieldBlock, FormBlockMixin):
  49. class Meta:
  50. label = _("Radios")
  51. icon = "list-ul"
  52. class CoderedStreamFormDropdownFieldBlock(form_blocks.DropdownFieldBlock, FormBlockMixin):
  53. class Meta:
  54. label = _("Dropdown")
  55. icon = "cr-list-alt"
  56. class CoderedStreamFormCheckboxesFieldBlock(form_blocks.CheckboxesFieldBlock, FormBlockMixin):
  57. class Meta:
  58. label = _("Checkboxes")
  59. icon = "list-ul"
  60. class CoderedStreamFormDateFieldBlock(form_blocks.DateFieldBlock, FormBlockMixin):
  61. class Meta:
  62. label = _("Date")
  63. icon = "date"
  64. field_class = CoderedDateField
  65. widget = CoderedDateInput
  66. class CoderedStreamFormTimeFieldBlock(form_blocks.TimeFieldBlock, FormBlockMixin):
  67. class Meta:
  68. label = _("Time")
  69. icon = "time"
  70. field_class = CoderedTimeField
  71. widget = CoderedTimeInput
  72. class CoderedStreamFormDateTimeFieldBlock(form_blocks.DateTimeFieldBlock, FormBlockMixin):
  73. class Meta:
  74. label = _("Date and Time")
  75. icon = "date"
  76. field_class = CoderedDateTimeField
  77. widget = CoderedDateTimeInput
  78. class CoderedStreamFormImageFieldBlock(form_blocks.ImageFieldBlock, FormBlockMixin):
  79. class Meta:
  80. label = _("Image Upload")
  81. icon = "image"
  82. class CoderedStreamFormFileFieldBlock(form_blocks.FileFieldBlock, FormBlockMixin):
  83. class Meta:
  84. label = _("Secure File Upload")
  85. icon = "upload"
  86. field_class = SecureFileField
  87. class CoderedStreamFormStepBlock(form_blocks.FormStepBlock):
  88. form_fields = blocks.StreamBlock()
  89. def __init__(self, local_blocks=None, **kwargs):
  90. super().__init__(
  91. local_blocks=[
  92. ('form_fields', blocks.StreamBlock(local_blocks))
  93. ]
  94. )