Skip to content

Commit

Permalink
New stream forms (#171)
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
Cory Sutyak authored and vsalvino committed May 16, 2019
1 parent 25cacfc commit dac2205
Show file tree
Hide file tree
Showing 30 changed files with 2,449 additions and 178 deletions.
26 changes: 25 additions & 1 deletion coderedcms/blocks/__init__.py
Expand Up @@ -5,22 +5,27 @@
"""

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 .stream_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'))),
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'), )),
('download', DownloadBlock()),
('embed_video', EmbedVideoBlock()),
('quote', QuoteBlock()),
Expand Down Expand Up @@ -64,3 +69,22 @@
),
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'))),
]

STREAMFORM_FIELDBLOCKS = [
('sf_singleline', CoderedStreamFormCharFieldBlock(group=_('Fields'))),
('sf_multiline', CoderedStreamFormTextFieldBlock(group=_('Fields'))),
('sf_number', CoderedStreamFormNumberFieldBlock(group=_('Fields'))),
('sf_checkboxes', CoderedStreamFormCheckboxesFieldBlock(group=_('Fields'))),
('sf_radios', CoderedStreamFormRadioButtonsFieldBlock(group=_('Fields'))),
('sf_dropdown', CoderedStreamFormDropdownFieldBlock(group=_('Fields'))),
('sf_checkbox', CoderedStreamFormCheckboxFieldBlock(group=_('Fields'))),
('sf_date', CoderedStreamFormDateFieldBlock(group=_('Fields'))),
('sf_time', CoderedStreamFormTimeFieldBlock(group=_('Fields'))),
('sf_datetime', CoderedStreamFormDateTimeFieldBlock(group=_('Fields'))),
('sf_image', CoderedStreamFormImageFieldBlock(group=_('Fields'))),
('sf_file', CoderedStreamFormFileFieldBlock(group=_('Fields'))),
]

STREAMFORM_BLOCKS = [
('step', CoderedStreamFormStepBlock(STREAMFORM_FIELDBLOCKS + HTML_STREAMBLOCKS)),
]
132 changes: 132 additions & 0 deletions coderedcms/blocks/stream_form_blocks.py
@@ -0,0 +1,132 @@
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 (
CoderedDateField, CoderedDateInput,
CoderedDateTimeField, CoderedDateTimeInput,
CoderedTimeField, CoderedTimeInput,
SecureFileField
)


class CoderedFormAdvSettings(CoderedAdvSettings):

condition_trigger_id = blocks.CharBlock(
required=False,
max_length=255,
label=_('Condition Trigger ID'),
help_text=_('The "Custom ID" of another field that that will trigger this field to be shown/hidden.')
)
condition_trigger_value = blocks.CharBlock(
required=False,
max_length=255,
label=_('Condition Trigger Value'),
help_text=_('The value of the field in "Condition Trigger ID" that will trigger this field to be shown.')
)


class FormBlockMixin(BaseBlock):
class Meta:
abstract=True

advsettings_class = CoderedFormAdvSettings


class CoderedStreamFormFieldBlock(form_blocks.OptionalFormFieldBlock, FormBlockMixin):
pass


class CoderedStreamFormCharFieldBlock(form_blocks.CharFieldBlock, FormBlockMixin):
class Meta:
label = _("Text or Email input")
icon = "fa-window-minimize"


class CoderedStreamFormTextFieldBlock(form_blocks.TextFieldBlock, FormBlockMixin):
class Meta:
label = _("Multi-line text")
icon = "fa-align-left"


class CoderedStreamFormNumberFieldBlock(form_blocks.NumberFieldBlock, FormBlockMixin):
class Meta:
label = _("Numbers only")
icon = "fa-hashtag"


class CoderedStreamFormCheckboxFieldBlock(form_blocks.CheckboxFieldBlock, FormBlockMixin):
class Meta:
label = _("Single Checkbox")
icon = "fa-check-square-o"


class CoderedStreamFormRadioButtonsFieldBlock(form_blocks.RadioButtonsFieldBlock, FormBlockMixin):
class Meta:
label = _("Radios")
icon = "fa-list-ul"


class CoderedStreamFormDropdownFieldBlock(form_blocks.DropdownFieldBlock, FormBlockMixin):
class Meta:
label = _("Dropdown")
icon = "fa-list-alt"


class CoderedStreamFormCheckboxesFieldBlock(form_blocks.CheckboxesFieldBlock, FormBlockMixin):
class Meta:
label = _("Checkboxes")
icon = "fa-list-ul"


class CoderedStreamFormDateFieldBlock(form_blocks.DateFieldBlock, FormBlockMixin):
class Meta:
label = _("Date")
icon = "fa-calendar"

field_class = CoderedDateField
widget = CoderedDateInput


class CoderedStreamFormTimeFieldBlock(form_blocks.TimeFieldBlock, FormBlockMixin):
class Meta:
label = _("Time")
icon = "fa-clock-o"

field_class = CoderedTimeField
widget = CoderedTimeInput


class CoderedStreamFormDateTimeFieldBlock(form_blocks.DateTimeFieldBlock, FormBlockMixin):
class Meta:
label = _("Date and Time")
icon = "fa-calendar"

field_class = CoderedDateTimeField
widget = CoderedDateTimeInput


class CoderedStreamFormImageFieldBlock(form_blocks.ImageFieldBlock, FormBlockMixin):
class Meta:
label = _("Image Upload")
icon = "fa-picture-o"


class CoderedStreamFormFileFieldBlock(form_blocks.FileFieldBlock, FormBlockMixin):
class Meta:
label = _("Secure File Upload")
icon = "fa-upload"

field_class = SecureFileField


class CoderedStreamFormStepBlock(form_blocks.FormStepBlock):
form_fields = blocks.StreamBlock()

def __init__(self, local_blocks=None, **kwargs):
super().__init__(
local_blocks = [
('form_fields', blocks.StreamBlock(local_blocks))
]
)
2 changes: 2 additions & 0 deletions coderedcms/forms.py 100644 → 100755
Expand Up @@ -122,6 +122,8 @@ def create_time_field(self, field, options):


class CoderedSubmissionsListView(WagtailSubmissionsListView):


def get_csv_response(self, context):
filename = self.get_csv_filename()
response = HttpResponse(content_type='text/csv; charset=utf-8')
Expand Down
@@ -0,0 +1,54 @@
# Generated by Django 2.2.1 on 2019-05-04 15:09

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'),
('coderedcms', '0014_classifiers'),
]

operations = [
migrations.CreateModel(
name='CoderedSubmissionRevision',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('type', models.CharField(choices=[('created', 'Created'), ('changed', 'Changed'), ('deleted', 'Deleted')], max_length=7)),
('created_at', models.DateTimeField(auto_now_add=True)),
('submission_id', models.TextField()),
('data', models.TextField()),
('summary', models.TextField()),
('submission_ct', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
],
options={
'ordering': ('-created_at',),
'abstract': False,
},
),
migrations.CreateModel(
name='CoderedSessionFormSubmission',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('form_data', models.TextField()),
('submit_time', models.DateTimeField(auto_now_add=True, verbose_name='submit time')),
('session_key', models.CharField(default=None, max_length=40, null=True)),
('thumbnails_by_path', models.TextField(default='{}')),
('last_modification', models.DateTimeField(auto_now=True, verbose_name='last modification')),
('status', models.CharField(choices=[('incomplete', 'Not submitted'), ('complete', 'Complete'), ('reviewed', 'Under consideration'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='incomplete', max_length=10)),
('page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.Page')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'form submission',
'unique_together': {('page', 'session_key'), ('page', 'user')},
'abstract': False,
'verbose_name_plural': 'form submissions',
},
),
]

0 comments on commit dac2205

Please sign in to comment.