Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make wagtail streamforms compatible with wagtail 4.1.1 #202

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
----------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


install_requires = [
"wagtail>=2,<2.17",
"wagtail>=2,<5",
"Unidecode>=0.04.14,<2.0",
]

Expand Down
2 changes: 1 addition & 1 deletion wagtailstreamforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions wagtailstreamforms/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 20 additions & 0 deletions wagtailstreamforms/migrations/0003_alter_form_fields.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
5 changes: 2 additions & 3 deletions wagtailstreamforms/models/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
MultiFieldPanel,
ObjectList,
PageChooserPanel,
StreamFieldPanel,
TabbedInterface,
)
from wagtail.core.models import Site
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -90,7 +89,7 @@ class AbstractForm(models.Model):
PageChooserPanel("post_redirect_page"),
]

field_panels = [StreamFieldPanel("fields")]
field_panels = [FieldPanel("fields")]

edit_handler = TabbedInterface(
[
Expand Down
4 changes: 2 additions & 2 deletions wagtailstreamforms/streamfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)