diff --git a/README.rst b/README.rst index a35614a6..8a5691b0 100644 --- a/README.rst +++ b/README.rst @@ -25,11 +25,17 @@ If you are using a version of wagtail 1.x, then the latest compatible version of $ pip install wagtailstreamforms<2 -Other wise you must install a version of this package from 2 onwards: +If you are using a version of wagtail 2.x, then the latest compatible version of this package is 3.19.1: .. code:: bash - $ pip install wagtailstreamforms>=2 + $ pip install wagtailstreamforms<3.19.2 + +Otherwise you must install a version of this package from 2 onwards: + +.. code:: bash + + $ pip install wagtailstreamforms>=3.19.2 What else is included? ---------------------- diff --git a/setup.py b/setup.py index 75c57602..c4e498f2 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ install_requires = [ - "wagtail>=2,<2.17", + "wagtail>=2,<5", "Unidecode>=0.04.14,<2.0", ] diff --git a/wagtailstreamforms/__init__.py b/wagtailstreamforms/__init__.py index 8403eee1..94774196 100644 --- a/wagtailstreamforms/__init__.py +++ b/wagtailstreamforms/__init__.py @@ -2,6 +2,6 @@ # major.minor.patch.release.number # release must be one of alpha, beta, rc, or final -VERSION = (3, 19, 1, "final", 1) +VERSION = (3, 19, 2, "final", 1) __version__ = get_version(VERSION) diff --git a/wagtailstreamforms/blocks.py b/wagtailstreamforms/blocks.py index c314028d..edcea8c9 100644 --- a/wagtailstreamforms/blocks.py +++ b/wagtailstreamforms/blocks.py @@ -39,6 +39,11 @@ def to_python(self, value): return self.target_model.objects.get(pk=value) except self.target_model.DoesNotExist: return None + + def get_form_state(self, value): + return self.field.widget.format_value( + self.field.prepare_value(self.value_for_form(value)) + ) class WagtailFormBlock(blocks.StructBlock): diff --git a/wagtailstreamforms/migrations/0003_alter_form_fields.py b/wagtailstreamforms/migrations/0003_alter_form_fields.py new file mode 100644 index 00000000..3f2e40ce --- /dev/null +++ b/wagtailstreamforms/migrations/0003_alter_form_fields.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.16 on 2022-11-25 10:19 + +from django.db import migrations +import wagtail.blocks +import wagtailstreamforms.streamfield + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailstreamforms', '0002_form_site'), + ] + + operations = [ + migrations.AlterField( + model_name='form', + name='fields', + field=wagtailstreamforms.streamfield.FormFieldsStreamField([('singleline', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False)), ('required', wagtail.blocks.BooleanBlock(required=False)), ('default_value', wagtail.blocks.CharBlock(required=False)), ('placeholder', wagtail.blocks.CharBlock(required=False))], icon='placeholder', label='Text field (single line)')), ('multiline', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False)), ('required', wagtail.blocks.BooleanBlock(required=False)), ('default_value', wagtail.blocks.CharBlock(required=False)), ('placeholder', wagtail.blocks.CharBlock(required=False))], icon='placeholder', label='Text field (multi line)')), ('email', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False)), ('required', wagtail.blocks.BooleanBlock(required=False)), ('default_value', wagtail.blocks.CharBlock(required=False)), ('placeholder', wagtail.blocks.CharBlock(required=False))], icon='mail', label=None)), ('dropdown', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False)), ('required', wagtail.blocks.BooleanBlock(required=False)), ('empty_label', wagtail.blocks.CharBlock(required=False)), ('choices', wagtail.blocks.ListBlock(wagtail.blocks.CharBlock(label='Option')))], icon='arrow-down-big', label='Dropdown field')), ('radio', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False)), ('required', wagtail.blocks.BooleanBlock(required=False)), ('choices', wagtail.blocks.ListBlock(wagtail.blocks.CharBlock(label='Option')))], icon='radio-empty', label='Radio buttons')), ('checkbox', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False)), ('required', wagtail.blocks.BooleanBlock(required=False))], icon='tick-inverse', label='Checkbox field')), ('singlefile', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False)), ('required', wagtail.blocks.BooleanBlock(required=False))], icon='doc-full-inverse', label='File field')), ('recaptcha', wagtail.blocks.StructBlock([('label', wagtail.blocks.CharBlock()), ('help_text', wagtail.blocks.CharBlock(required=False))], icon='success', label='ReCAPTCHA field'))], use_json_field=True, verbose_name='Fields'), + ), + ] diff --git a/wagtailstreamforms/models/form.py b/wagtailstreamforms/models/form.py index c9f06314..0eb548ff 100644 --- a/wagtailstreamforms/models/form.py +++ b/wagtailstreamforms/models/form.py @@ -8,7 +8,6 @@ MultiFieldPanel, ObjectList, PageChooserPanel, - StreamFieldPanel, TabbedInterface, ) from wagtail.core.models import Site @@ -43,7 +42,7 @@ class AbstractForm(models.Model): template_name = models.CharField( _("Template"), max_length=255, choices=get_setting("FORM_TEMPLATES") ) - fields = FormFieldsStreamField([], verbose_name=_("Fields")) + fields = FormFieldsStreamField([], verbose_name=_("Fields"), use_json_field=True) submit_button_text = models.CharField( _("Submit button text"), max_length=100, default="Submit" ) @@ -90,7 +89,7 @@ class AbstractForm(models.Model): PageChooserPanel("post_redirect_page"), ] - field_panels = [StreamFieldPanel("fields")] + field_panels = [FieldPanel("fields")] edit_handler = TabbedInterface( [ diff --git a/wagtailstreamforms/streamfield.py b/wagtailstreamforms/streamfield.py index 454b9be3..5e5d321d 100644 --- a/wagtailstreamforms/streamfield.py +++ b/wagtailstreamforms/streamfield.py @@ -43,6 +43,6 @@ def dependencies(self): class FormFieldsStreamField(StreamField): - def __init__(self, block_types, **kwargs): - super().__init__(block_types, **kwargs) + def __init__(self, block_types, use_json_field=None, **kwargs): + super().__init__(block_types, use_json_field=use_json_field, **kwargs) self.stream_block = FormFieldStreamBlock(block_types, required=not self.blank)