Skip to content
Snippets Groups Projects
Commit 94e2f350 authored by jan.bednarik's avatar jan.bednarik
Browse files

uniweb: Form page

parent 6cd9ffc3
No related branches found
No related tags found
2 merge requests!206Release,!205Uniweb
Pipeline #2839 passed
...@@ -51,6 +51,7 @@ INSTALLED_APPS = [ ...@@ -51,6 +51,7 @@ INSTALLED_APPS = [
"search", "search",
"regulace_konopi", "regulace_konopi",
"green_deal", "green_deal",
"widget_tweaks",
"wagtail.contrib.forms", "wagtail.contrib.forms",
"wagtail.contrib.redirects", "wagtail.contrib.redirects",
"wagtail.contrib.modeladmin", "wagtail.contrib.modeladmin",
......
This diff is collapsed.
This diff is collapsed.
# Generated by Django 3.1.7 on 2021-03-28 23:20
import wagtail.contrib.table_block.blocks
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("uniweb", "0016_auto_20210326_1801"),
]
operations = [
migrations.AlterField(
model_name="uniwebformpage",
name="content_landing",
field=wagtail.core.fields.StreamField(
[
(
"title",
wagtail.core.blocks.CharBlock(
group="nadpisy",
icon="title",
label="nadpis",
template="uniweb/blocks/title.html",
),
),
(
"advanced_title",
wagtail.core.blocks.StructBlock(
[
(
"align",
wagtail.core.blocks.ChoiceBlock(
choices=[
("left", "vlevo"),
("center", "uprostřed"),
("right", "vpravo"),
],
label="zarovnání",
),
),
(
"color",
wagtail.core.blocks.ChoiceBlock(
choices=[
("black_on_white", "černá na bílé"),
("white_on_black", "bílá na černé"),
("white_on_blue", "bílá na modré"),
("white_on_cyan", "bílá na tyrkysové"),
("white_on_violet", "bílá na fialové"),
],
label="barva",
),
),
(
"title",
wagtail.core.blocks.CharBlock(label="nadpis"),
),
]
),
),
(
"picture_title",
wagtail.core.blocks.StructBlock(
[
(
"color",
wagtail.core.blocks.ChoiceBlock(
choices=[
("black_on_white", "černá na bílé"),
("white_on_black", "bílá na černé"),
("white_on_blue", "bílá na modré"),
("white_on_cyan", "bílá na tyrkysové"),
("white_on_violet", "bílá na fialové"),
],
label="barva",
),
),
(
"title",
wagtail.core.blocks.CharBlock(label="nadpis"),
),
(
"picture",
wagtail.images.blocks.ImageChooserBlock(
help_text="rozměr na výšku 75px nebo více (obrázek bude zmenšen na výšku 75px)",
label="obrázek",
),
),
]
),
),
(
"text",
wagtail.core.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"image",
"superscript",
"subscript",
"strikethrough",
"blockquote",
],
group="texty",
label="text",
template="uniweb/blocks/text.html",
),
),
(
"advanced_text",
wagtail.core.blocks.StructBlock(
[
(
"align",
wagtail.core.blocks.ChoiceBlock(
choices=[
("left", "vlevo"),
("center", "uprostřed"),
("right", "vpravo"),
],
label="zarovnání",
),
),
(
"color",
wagtail.core.blocks.ChoiceBlock(
choices=[
("black_on_white", "černá na bílé"),
("white_on_black", "bílá na černé"),
("white_on_blue", "bílá na modré"),
("white_on_cyan", "bílá na tyrkysové"),
("white_on_violet", "bílá na fialové"),
],
label="barva",
),
),
(
"text",
wagtail.core.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"image",
"superscript",
"subscript",
"strikethrough",
"blockquote",
],
label="text",
),
),
]
),
),
(
"text_columns",
wagtail.core.blocks.StructBlock(
[
(
"left_text",
wagtail.core.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"image",
"superscript",
"subscript",
"strikethrough",
"blockquote",
],
label="levý sloupec",
),
),
(
"right_text",
wagtail.core.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"image",
"superscript",
"subscript",
"strikethrough",
"blockquote",
],
label="pravý sloupec",
),
),
]
),
),
(
"advanced_text_columns",
wagtail.core.blocks.StructBlock(
[
(
"align",
wagtail.core.blocks.ChoiceBlock(
choices=[
("left", "vlevo"),
("center", "uprostřed"),
("right", "vpravo"),
],
label="zarovnání",
),
),
(
"color",
wagtail.core.blocks.ChoiceBlock(
choices=[
("black_on_white", "černá na bílé"),
("white_on_black", "bílá na černé"),
("white_on_blue", "bílá na modré"),
("white_on_cyan", "bílá na tyrkysové"),
("white_on_violet", "bílá na fialové"),
],
label="barva",
),
),
(
"left_text",
wagtail.core.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"image",
"superscript",
"subscript",
"strikethrough",
"blockquote",
],
label="levý sloupec",
),
),
(
"right_text",
wagtail.core.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"image",
"superscript",
"subscript",
"strikethrough",
"blockquote",
],
label="pravý sloupec",
),
),
]
),
),
(
"gallery",
wagtail.core.blocks.ListBlock(
wagtail.images.blocks.ImageChooserBlock(label="obrázek"),
group="ostatní",
icon="image",
label="galerie",
template="uniweb/blocks/gallery.html",
),
),
(
"picture_list",
wagtail.core.blocks.StructBlock(
[
(
"color",
wagtail.core.blocks.ChoiceBlock(
choices=[
("black_on_white", "černá na bílé"),
("white_on_black", "bílá na černé"),
("white_on_blue", "bílá na modré"),
("white_on_cyan", "bílá na tyrkysové"),
("white_on_violet", "bílá na fialové"),
],
label="barva",
),
),
(
"items",
wagtail.core.blocks.ListBlock(
wagtail.core.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"image",
"superscript",
"subscript",
"strikethrough",
"blockquote",
],
label="odstavec",
),
label="odstavce",
),
),
(
"picture",
wagtail.images.blocks.ImageChooserBlock(
help_text="rozměr 25x25px nebo více (obrázek bude zmenšen na 25x25px)",
label="obrázek",
),
),
]
),
),
(
"table",
wagtail.contrib.table_block.blocks.TableBlock(
group="ostatní",
label="tabulka",
template="uniweb/blocks/table.html",
),
),
(
"articles",
wagtail.core.blocks.StructBlock(
[
(
"page",
wagtail.core.blocks.PageChooserBlock(
label="sekce článků",
page_type=["uniweb.UniwebArticlesIndexPage"],
),
),
(
"lines",
wagtail.core.blocks.IntegerBlock(
default=1,
help_text="zobrazí se tři články na řádek",
label="počet řádků",
),
),
]
),
),
],
blank=True,
verbose_name="obsah stránky zobrazené po odeslání formuláře",
),
),
]
...@@ -8,12 +8,15 @@ from taggit.models import TaggedItemBase ...@@ -8,12 +8,15 @@ from taggit.models import TaggedItemBase
from wagtail.admin.edit_handlers import ( from wagtail.admin.edit_handlers import (
FieldPanel, FieldPanel,
HelpPanel, HelpPanel,
InlinePanel,
MultiFieldPanel, MultiFieldPanel,
ObjectList, ObjectList,
PublishingPanel, PublishingPanel,
StreamFieldPanel, StreamFieldPanel,
TabbedInterface, TabbedInterface,
) )
from wagtail.contrib.forms.edit_handlers import FormSubmissionsPanel
from wagtail.contrib.forms.models import AbstractForm, AbstractFormField
from wagtail.contrib.table_block.blocks import TableBlock from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.core import blocks from wagtail.core import blocks
from wagtail.core.fields import StreamField from wagtail.core.fields import StreamField
...@@ -185,6 +188,7 @@ class MenuItemBlock(blocks.StructBlock): ...@@ -185,6 +188,7 @@ class MenuItemBlock(blocks.StructBlock):
"uniweb.UniwebHomePage", "uniweb.UniwebHomePage",
"uniweb.UniwebFlexiblePage", "uniweb.UniwebFlexiblePage",
"uniweb.UniwebArticlesIndexPage", "uniweb.UniwebArticlesIndexPage",
"uniweb.UniwebFormPage",
], ],
) )
...@@ -192,68 +196,64 @@ class MenuItemBlock(blocks.StructBlock): ...@@ -192,68 +196,64 @@ class MenuItemBlock(blocks.StructBlock):
label = "stránka" label = "stránka"
class UniwebContentMixin(models.Model): CONTENT_STREAM_BLOCKS = [
content = StreamField( (
[ "title",
( blocks.CharBlock(
"title", label="nadpis",
blocks.CharBlock( icon="title",
label="nadpis", group="nadpisy",
icon="title", template="uniweb/blocks/title.html",
group="nadpisy", ),
template="uniweb/blocks/title.html", ),
), ("advanced_title", AdvancedTitleBlock()),
), ("picture_title", PictureTitleBlock()),
("advanced_title", AdvancedTitleBlock()), (
("picture_title", PictureTitleBlock()), "text",
( blocks.RichTextBlock(
"text", label="text",
blocks.RichTextBlock( features=RICH_TEXT_FEATURES,
label="text", group="texty",
features=RICH_TEXT_FEATURES, template="uniweb/blocks/text.html",
group="texty", ),
template="uniweb/blocks/text.html", ),
), ("advanced_text", AdvancedTextBlock()),
), ("text_columns", ColumnsTextBlock()),
("advanced_text", AdvancedTextBlock()), ("advanced_text_columns", AdvancedColumnsTextBlock()),
("text_columns", ColumnsTextBlock()), (
("advanced_text_columns", AdvancedColumnsTextBlock()), "gallery",
( blocks.ListBlock(
"gallery", ImageChooserBlock(label="obrázek"),
blocks.ListBlock( label="galerie",
ImageChooserBlock(label="obrázek"), icon="image",
label="galerie", group="ostatní",
icon="image", template="uniweb/blocks/gallery.html",
group="ostatní", ),
template="uniweb/blocks/gallery.html", ),
), ("picture_list", PictureListBlock()),
), (
("picture_list", PictureListBlock()), "table",
( TableBlock(
"table", label="tabulka",
TableBlock( group="ostatní",
label="tabulka", template="uniweb/blocks/table.html",
group="ostatní", ),
template="uniweb/blocks/table.html", ),
), ("articles", ArticlesBlock()),
), ]
("articles", ArticlesBlock()),
],
verbose_name="obsah stránky",
blank=True,
)
class Meta:
abstract = True
class UniwebArticleTag(TaggedItemBase): class UniwebArticleTag(TaggedItemBase):
content_object = ParentalKey("uniweb.UniwebArticlePage", on_delete=models.CASCADE) content_object = ParentalKey("uniweb.UniwebArticlePage", on_delete=models.CASCADE)
class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin): class UniwebHomePage(Page, MetadataPageMixin):
### FIELDS ### FIELDS
content = StreamField(
CONTENT_STREAM_BLOCKS, verbose_name="obsah stránky", blank=True
)
# settings # settings
matomo_id = models.IntegerField( matomo_id = models.IntegerField(
"Matomo ID pro sledování návštěvnosti", blank=True, null=True "Matomo ID pro sledování návštěvnosti", blank=True, null=True
...@@ -315,6 +315,7 @@ class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin): ...@@ -315,6 +315,7 @@ class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin):
subpage_types = [ subpage_types = [
"uniweb.UniwebFlexiblePage", "uniweb.UniwebFlexiblePage",
"uniweb.UniwebArticlesIndexPage", "uniweb.UniwebArticlesIndexPage",
"uniweb.UniwebFormPage",
] ]
### OTHERS ### OTHERS
...@@ -327,9 +328,13 @@ class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin): ...@@ -327,9 +328,13 @@ class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin):
return self return self
class UniwebFlexiblePage(Page, UniwebContentMixin, SubpageMixin, MetadataPageMixin): class UniwebFlexiblePage(Page, SubpageMixin, MetadataPageMixin):
### FIELDS ### FIELDS
content = StreamField(
CONTENT_STREAM_BLOCKS, verbose_name="obsah stránky", blank=True
)
### PANELS ### PANELS
promote_panels = [ promote_panels = [
...@@ -353,8 +358,12 @@ class UniwebFlexiblePage(Page, UniwebContentMixin, SubpageMixin, MetadataPageMix ...@@ -353,8 +358,12 @@ class UniwebFlexiblePage(Page, UniwebContentMixin, SubpageMixin, MetadataPageMix
### RELATIONS ### RELATIONS
parent_page_types = ["uniweb.UniwebHomePage", "uniweb.UniwebFlexiblePage"] parent_page_types = [
subpage_types = ["uniweb.UniwebFlexiblePage"] "uniweb.UniwebHomePage",
"uniweb.UniwebFlexiblePage",
"uniweb.UniwebFormPage",
]
subpage_types = ["uniweb.UniwebFlexiblePage", "uniweb.UniwebFormPage"]
### OTHERS ### OTHERS
...@@ -454,3 +463,74 @@ class UniwebArticlePage(Page, ArticleMixin, SubpageMixin, MetadataPageMixin): ...@@ -454,3 +463,74 @@ class UniwebArticlePage(Page, ArticleMixin, SubpageMixin, MetadataPageMixin):
.order_by("-uniwebarticlepage__date")[:3] .order_by("-uniwebarticlepage__date")[:3]
) )
return context return context
class UniwebFormField(AbstractFormField):
page = ParentalKey(
"UniwebFormPage", on_delete=models.CASCADE, related_name="form_fields"
)
class UniwebFormPage(AbstractForm, SubpageMixin, MetadataPageMixin):
### FIELDS
content_before = StreamField(
CONTENT_STREAM_BLOCKS, verbose_name="obsah stránky před formulářem", blank=True
)
content_after = StreamField(
CONTENT_STREAM_BLOCKS, verbose_name="obsah stránky za formulářem", blank=True
)
content_landing = StreamField(
CONTENT_STREAM_BLOCKS,
verbose_name="obsah stránky zobrazené po odeslání formuláře",
blank=True,
)
### PANELS
content_panels = AbstractForm.content_panels + [
FormSubmissionsPanel(),
StreamFieldPanel("content_before"),
InlinePanel("form_fields", label="formulář"),
StreamFieldPanel("content_after"),
StreamFieldPanel("content_landing"),
]
promote_panels = [
MultiFieldPanel(
[
FieldPanel("slug"),
FieldPanel("seo_title"),
FieldPanel("search_description"),
ImageChooserPanel("search_image"),
HelpPanel(help.build(help.NO_SEO_TITLE, help.NO_SEARCH_IMAGE)),
],
gettext_lazy("Common page configuration"),
),
]
submissions_panels = [
FormSubmissionsPanel(),
]
edit_handler = TabbedInterface(
[
ObjectList(content_panels, heading=gettext_lazy("Content")),
ObjectList(promote_panels, heading=gettext_lazy("Promote")),
ObjectList(submissions_panels, heading="Data z formuláře"),
]
)
### RELATIONS
parent_page_types = [
"uniweb.UniwebHomePage",
"uniweb.UniwebFlexiblePage",
"uniweb.UniwebFormPage",
]
subpage_types = ["uniweb.UniwebFlexiblePage", "uniweb.UniwebFormPage"]
### OTHERS
class Meta:
verbose_name = "Formulářová stránka"
{% load wagtailcore_tags wagtailimages_tags %} {% load wagtailcore_tags %}
{% for block in page.content %} {% for block in page.content %}
......
{% extends "uniweb/base.html" %}
{% load wagtailcore_tags widget_tweaks %}
{% block content %}
<main>
{% for block in page.content_before %}
{% include_block block with first=forloop.first %}
{% endfor %}
<div class="content-block px-4 py-2 clearfix">
<form action="{% pageurl page %}" method="post">
{% csrf_token %}
{% for hidden_field in form.hidden_fields %}
{{ hidden_field.errors }}
{{ hidden_field }}
{% endfor %}
<div class="grid grid-cols-2 gap-4 row-gap-6 max-w-xl">
{% for field in form.visible_fields %}
<div class="form-field col-span-2 {% if field.field.required %}form-field--required{% endif %}">
{% if field.widget_type == "select" %}
<label class="form-field__label" for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="form-field__wrapper form-field__wrapper--shadowed">
<div class="select">
{{ field|add_class:"select__control form-field__control" }}
</div>
</div>
{% elif field.widget_type == "radioselect" %}
<label class="form-field__label" for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="form-field__wrapper py-1 flex flex-col">
{% for radio in field %}
<div class="my-1">
<div class="radio form-field__control">
{{ radio }}
</div>
</div>
{% endfor %}
</div>
{% elif field.widget_type == "checkboxselectmultiple" %}
<label class="form-field__label mt-2" for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="form-field__wrapper py-1 flex flex-col">
{% for checkbox in field %}
<div class="my-1">
<div class="checkbox form-field__control">
{{ checkbox.tag }}
<label for="{{ checkbox.id_for_label }}">{{ checkbox.choice_label }}</label>
</div>
</div>
{% endfor %}
</div>
{% elif field.widget_type == "checkbox" %}
<div class="form-field__wrapper mt-2">
<div class="checkbox form-field__control">
{{ field }}
<label class="form-field__label" for="{{ field.id_for_label }}">{{ field.label }}</label>
</div>
</div>
{% else %}
<label class="form-field__label" for="{{ field.id_for_label }}">{{ field.label }} ({{ field.widget_type }})</label>
<div class="form-field__wrapper form-field__wrapper--shadowed">
{{ field|add_class:"text-input form-field__control" }}
</div>
{% endif %}
{% if field.help_text %}
<div class="form-field__help-text">{{ field.help_text }}</div>
{% endif %}
{% if field.errors %}
<div class="form-field__error">{{ field.errors }}</div>
{% endif %}
</div>
{% endfor %}
</div>
<button class="btn text-lg mt-6 mb-4 btn--black-100">
<div class="btn__body ">odeslat</div>
</button>
</form>
</div>
{% for block in page.content_after %}
{% include_block block %}
{% endfor %}
</main>
{% endblock %}
{% extends "uniweb/base.html" %}
{% load wagtailcore_tags %}
{% block content %}
<main>
{% for block in page.content_landing %}
{% include_block block with first=forloop.first %}
{% endfor %}
</main>
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment