-
Notifications
You must be signed in to change notification settings - Fork 136
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
Feature streamforms #171
Feature streamforms #171
Changes from 6 commits
3414df4
0c21511
10a3b2d
d10e7f4
f26952a
ed5cec5
f404489
4eb65ec
460fd48
e053aaa
e5a2210
e6b7579
f851200
8584baa
d6887a7
5becba8
4551ee5
aececf6
2dfd903
b31cd2a
5aa5104
d95fe4b
babd278
0dc6b12
ce5b1f9
230b5eb
eef7deb
83f7c5d
5c89bad
30bc9aa
2f340c2
13a9ca9
93b12df
b7fa35b
3e347ba
d01bba7
90f19dd
6b2c59b
3d2b9a1
9c0f7ac
d30266a
c39da67
85f0be0
789a2c3
f401008
16f5d47
c841d07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,49 +5,54 @@ | |
""" | ||
|
||
from django.utils.translation import ugettext_lazy as _ | ||
from wagtail.core.blocks import CharBlock, StreamBlock, StructBlock | ||
|
||
from coderedcms.wagtail_flexible_forms.blocks import FormStepBlock, FormStepsBlock | ||
|
||
from .advanced_form_blocks import * #noqa | ||
from .base_blocks import * #noqa | ||
from .html_blocks import * #noqa | ||
from .metadata_blocks import * #noqa | ||
from .content_blocks import * #noqa | ||
from .layout_blocks import * #noqa | ||
|
||
|
||
|
||
# Collections of blocks commonly used together. | ||
|
||
HTML_STREAMBLOCKS = [ | ||
('text', RichTextBlock(icon='fa-file-text-o')), | ||
('button', ButtonBlock()), | ||
('image', ImageBlock()), | ||
('image_link', ImageLinkBlock()), | ||
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'))), | ||
('download', DownloadBlock()), | ||
('embed_video', EmbedVideoBlock()), | ||
('quote', QuoteBlock()), | ||
('table', TableBlock()), | ||
('google_map', EmbedGoogleMapBlock()), | ||
('page_list', PageListBlock()), | ||
('page_preview', PagePreviewBlock()), | ||
('text', RichTextBlock(icon='fa-file-text-o', group=_('HTML'))), | ||
('button', ButtonBlock(group=_('HTML'))), | ||
('image', ImageBlock(group=_('HTML'))), | ||
('image_link', ImageLinkBlock(group=_('HTML'))), | ||
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'), group=_('HTML'))), | ||
('download', DownloadBlock(group=_('HTML'))), | ||
('embed_video', EmbedVideoBlock(group=_('HTML'))), | ||
('quote', QuoteBlock(group=_('HTML'))), | ||
('table', TableBlock(group=_('HTML'))), | ||
('google_map', EmbedGoogleMapBlock(group=_('HTML'))), | ||
('page_list', PageListBlock(group=_('HTML'))), | ||
('page_preview', PagePreviewBlock(group=_('HTML'))), | ||
] | ||
|
||
CONTENT_STREAMBLOCKS = HTML_STREAMBLOCKS + [ | ||
('card', CardBlock()), | ||
('carousel', CarouselBlock()), | ||
('image_gallery', ImageGalleryBlock()), | ||
('modal', ModalBlock(HTML_STREAMBLOCKS)), | ||
('pricelist', PriceListBlock()), | ||
('reusable_content', ReusableContentBlock()), | ||
('card', CardBlock(group=_('Content'))), | ||
('carousel', CarouselBlock(group=_('Content'))), | ||
('image_gallery', ImageGalleryBlock(group=_('Content'))), | ||
('modal', ModalBlock(HTML_STREAMBLOCKS, group=_('Content'))), | ||
('pricelist', PriceListBlock(group=_('Content'))), | ||
('reusable_content', ReusableContentBlock(group=_('Content'))), | ||
] | ||
|
||
NAVIGATION_STREAMBLOCKS = [ | ||
('page_link', NavPageLinkWithSubLinkBlock()), | ||
('external_link', NavExternalLinkWithSubLinkBlock()), | ||
('document_link', NavDocumentLinkWithSubLinkBlock()), | ||
('page_link', NavPageLinkWithSubLinkBlock(group=_('Navigation'))), | ||
('external_link', NavExternalLinkWithSubLinkBlock(group=_('Navigation'))), | ||
('document_link', NavDocumentLinkWithSubLinkBlock(group=_('Navigation'))), | ||
] | ||
|
||
BASIC_LAYOUT_STREAMBLOCKS = [ | ||
('row', GridBlock(HTML_STREAMBLOCKS)), | ||
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'))), | ||
('row', GridBlock(HTML_STREAMBLOCKS, group=('Layout'))), | ||
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'), group=('Layout'))), | ||
] | ||
|
||
LAYOUT_STREAMBLOCKS = [ | ||
|
@@ -64,3 +69,28 @@ | |
), | ||
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'))), | ||
] | ||
|
||
ADVANCEDFORM_FORMBLOCKS = [ | ||
('single_line', CoderedAdvancedFormCharFieldBlock(group=_('Fields'))), | ||
('multi_line', CoderedAdvancedFormTextFieldBlock(group=_('Fields'))), | ||
('number', CoderedAdvancedFormNumberFieldBlock(group=_('Fields'))), | ||
('checkbox', CoderedAdvancedFormCheckboxFieldBlock(group=_('Fields'))), | ||
('radios', CoderedAdvancedFormRadioButtonsFieldBlock(group=_('Fields'))), | ||
('dropdown', CoderedAdvancedFormDropdownFieldBlock(group=_('Fields'))), | ||
('checkboxes', CoderedAdvancedFormCheckboxesFieldBlock(group=_('Fields'))), | ||
('date', CoderedAdvancedFormDateFieldBlock(group=_('Fields'))), | ||
('time', CoderedAdvancedFormTimeFieldBlock(group=_('Fields'))), | ||
('datetime', CoderedAdvancedFormDateTimeFieldBlock(group=_('Fields'))), | ||
('image', CoderedAdvancedFormImageFieldBlock(group=_('Fields'))), | ||
('file', CoderedAdvancedFormFileFieldBlock(group=_('Fields'))), | ||
] | ||
|
||
|
||
ADVANCEDFORM_STREAMBLOCKS = ADVANCEDFORM_FORMBLOCKS + CONTENT_STREAMBLOCKS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking HTML_STREAMBLOCKS would be a better idea here instead of CONTENT_STREAMBLOCKS, to avoid making the form's streamfield too massive. I don't think it would be good to intermingle form inputs with deeply nested content blocks. |
||
|
||
class CoderedAdvancedFormStepBlock(FormStepBlock): | ||
form_fields = StreamBlock(ADVANCEDFORM_STREAMBLOCKS) | ||
|
||
|
||
class CoderedAdvancedFormStepsBlock(FormStepsBlock): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like defining classes here in this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would get a circular dependency error if it was in |
||
step = CoderedAdvancedFormStepBlock() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
from wagtail.core import blocks | ||
|
||
|
||
from coderedcms.wagtail_flexible_forms import blocks as form_blocks | ||
from coderedcms.blocks.base_blocks import BaseBlock, CoderedAdvSettings | ||
from coderedcms.forms import SecureFileField | ||
|
||
|
||
class CoderedFormAdvSettings(CoderedAdvSettings): | ||
|
||
conditional_name = blocks.CharBlock( | ||
required=False, | ||
max_length=255, | ||
label=_('Conditional Name'), | ||
help_text=_('The name used to identify this block for other blocks to target as a condition.') | ||
) | ||
conditional_target_name = blocks.CharBlock( | ||
required=False, | ||
max_length=255, | ||
label=_('Conditional Target Name'), | ||
help_text=_('The name of the block that will be this block\'s condition.') | ||
) | ||
conditional_target_value = blocks.CharBlock( | ||
required=False, | ||
max_length=255, | ||
label=_('Conditional Target Value'), | ||
help_text=_('The value of this block\'s condition that is required to show this block on the form.') | ||
) | ||
|
||
|
||
class FormBlockMixin(BaseBlock): | ||
class Meta: | ||
abstract=True | ||
|
||
advsettings_class = CoderedFormAdvSettings | ||
|
||
|
||
class CoderedAdvancedFormFieldBlock(form_blocks.OptionalFormFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormCharFieldBlock(form_blocks.CharFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormTextFieldBlock(form_blocks.TextFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormNumberFieldBlock(form_blocks.NumberFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormCheckboxFieldBlock(form_blocks.CheckboxFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormRadioButtonsFieldBlock(form_blocks.RadioButtonsFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormDropdownFieldBlock(form_blocks.DropdownFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormCheckboxesFieldBlock(form_blocks.CheckboxesFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormDateFieldBlock(form_blocks.DateFieldBlock, FormBlockMixin): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the problem is here, but the Date/Time/Datetime blocks are not rendering with the correct html |
||
pass | ||
|
||
|
||
class CoderedAdvancedFormTimeFieldBlock(form_blocks.TimeFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormDateTimeFieldBlock(form_blocks.DateTimeFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormImageFieldBlock(form_blocks.ImageFieldBlock, FormBlockMixin): | ||
pass | ||
|
||
|
||
class CoderedAdvancedFormFileFieldBlock(form_blocks.FileFieldBlock, FormBlockMixin): | ||
field_class = SecureFileField |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 2.2 on 2019-04-30 21:06 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtail_flexible_forms', '__first__'), | ||
('coderedcms', '0014_classifiers'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CoderedSessionFormSubmission', | ||
fields=[ | ||
], | ||
options={ | ||
'proxy': True, | ||
'indexes': [], | ||
}, | ||
bases=('wagtail_flexible_forms.sessionformsubmission',), | ||
), | ||
] |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my concern here is that this will potentially cause migrations from hell once we have to switch to built-in wagtail streamforms. I'm wondering if we should wrap/extend any blocks or concrete models in
wagtail_flexible_forms
, that way all the migrations are pointing to our models, and we can update under the hood as necessary. I only say that because a similar thing happened when we switched from wagtail's built-in RichTextBlock to our own RichTextBlock, and I had to do a bunch of find&replace in migration files in client projects to resolve.I'm not 100% sure if it will cause problems or not, just trying to be proactive. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CoderedAdvancedFormPage
uses the extendedCoderedFormStepBlock
which inherits from theirFormStepBlock
. All of our File Fields are using extended versions of their file fields. The only thing that we might want to do related to this concern is to only use wff as a library and extend theirStreamFormMixin
andStep
/Steps
classes in the CMS so there is no direct contact between the CMS and wff.