Skip to content
Snippets Groups Projects
Commit 2da70355 authored by Alexa Valentová's avatar Alexa Valentová
Browse files

Fix uniweb ecomail integration, center form

parent a3a56792
No related branches found
No related tags found
2 merge requests!1285Fix uniweb ecomail integration, center form,!1284Fix uniweb ecomail integration, center form
Pipeline #20858 passed
...@@ -84,7 +84,11 @@ ...@@ -84,7 +84,11 @@
</div> </div>
{% endfor %} {% endfor %}
{% include "styleguide2/includes/atoms/buttons/round_button_form.html" with show_arrow_on_hover=True text="Odeslat" %} {% if page.submission_button_text %}
{% include "styleguide2/includes/atoms/buttons/round_button_form.html" with show_arrow_on_hover=True text=page.submission_button_text %}
{% else %}
{% include "styleguide2/includes/atoms/buttons/round_button_form.html" with show_arrow_on_hover=True text="Odeslat" %}
{% endif %}
</form> </form>
{% for block in page.content_after %} {% for block in page.content_after %}
......
# Generated by Django 5.0.7 on 2025-03-26 08:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('uniweb', '0135_uniwebformpage_subscribe_to_ecomail'),
]
operations = [
migrations.AddField(
model_name='uniwebformpage',
name='email_field_id',
field=models.CharField(blank=True, null=True, verbose_name='ID email fieldu'),
),
migrations.AddField(
model_name='uniwebformpage',
name='name_and_surname_field_id',
field=models.CharField(blank=True, null=True, verbose_name='ID jméno & příjmení fieldu'),
),
]
# Generated by Django 5.0.7 on 2025-03-26 08:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('uniweb', '0136_uniwebformpage_email_field_id_and_more'),
]
operations = [
migrations.AddField(
model_name='uniwebformpage',
name='submission_button_text',
field=models.CharField(default='Odeslat', verbose_name='Text tlačítka pro odeslání formuláře'),
),
]
...@@ -29,6 +29,7 @@ from shared.blocks import ( ...@@ -29,6 +29,7 @@ from shared.blocks import (
NewsletterSubscriptionBlock, NewsletterSubscriptionBlock,
) )
from shared.const import RICH_TEXT_DEFAULT_FEATURES from shared.const import RICH_TEXT_DEFAULT_FEATURES
from shared.utils import subscribe_to_ecomail_newsletter
from shared.models import ( from shared.models import (
CalendarMixin, CalendarMixin,
CustomLogoMixin, CustomLogoMixin,
...@@ -501,6 +502,23 @@ class UniwebFormPage( ...@@ -501,6 +502,23 @@ class UniwebFormPage(
default=False, default=False,
) )
name_and_surname_field_id = models.CharField(
verbose_name="ID jméno & příjmení fieldu",
blank=True,
null=True
)
email_field_id = models.CharField(
verbose_name="ID email fieldu",
blank=True,
null=True
)
submission_button_text = models.CharField(
verbose_name="Text tlačítka pro odeslání formuláře",
default="Odeslat",
)
### PANELS ### PANELS
content_panels = AbstractForm.content_panels + [ content_panels = AbstractForm.content_panels + [
...@@ -508,6 +526,7 @@ class UniwebFormPage( ...@@ -508,6 +526,7 @@ class UniwebFormPage(
FieldPanel("show_transparent_header"), FieldPanel("show_transparent_header"),
FieldPanel("content_before"), FieldPanel("content_before"),
InlinePanel("form_fields", label="formulář"), InlinePanel("form_fields", label="formulář"),
FieldPanel("submission_button_text"),
FieldPanel("content_after"), FieldPanel("content_after"),
FieldPanel("content_landing"), FieldPanel("content_landing"),
] ]
...@@ -516,7 +535,12 @@ class UniwebFormPage( ...@@ -516,7 +535,12 @@ class UniwebFormPage(
submissions_panels = [FormSubmissionsPanel()] submissions_panels = [FormSubmissionsPanel()]
advanced_panels = [FieldPanel("show_in_parent_page"), FieldPanel("subscribe_to_ecomail")] advanced_panels = [
FieldPanel("show_in_parent_page"),
FieldPanel("subscribe_to_ecomail"),
FieldPanel("name_and_surname_field_id"),
FieldPanel("email_field_id"),
]
edit_handler = TabbedInterface( edit_handler = TabbedInterface(
[ [
...@@ -540,13 +564,51 @@ class UniwebFormPage( ...@@ -540,13 +564,51 @@ class UniwebFormPage(
def serve(self, request): def serve(self, request):
if request.method == "GET" and self.show_in_parent_page: if request.method == "GET" and self.show_in_parent_page:
if hasattr(self, "parent_page"): if hasattr(self, "root_page"):
return redirect(self.parent_page.url) return redirect(self.root_page.url)
else: else:
return redirect("/") return redirect("/")
return super().serve(request) return super().serve(request)
def process_form_submission(self, form):
cleaned_data = form.cleaned_data
if (
hasattr(self, "root_page") and self.root_page
and self.subscribe_to_ecomail
and self.name_and_surname_field_id in cleaned_data
and self.email_field_id in cleaned_data
):
name_and_surname = cleaned_data[self.name_and_surname_field_id]
name_and_surname = name_and_surname.split(" ")
name = ""
surname = ""
if len(name_and_surname) > 1:
name = name_and_surname[0]
surname = " ".join(name_and_surname[1:])
else:
name = name_and_surname[0]
custom_data = {
"name": name,
}
if surname != "":
custom_data["surname"] = surname
subscribe_to_ecomail_newsletter(
cleaned_data[self.email_field_id],
self.root_page.ecomail_newsletter_list_tags,
self.root_page.ecomail_newsletter_list_source,
self.root_page.ecomail_newsletter_list_id,
custom_data
)
super().process_form_submission(form)
class Meta: class Meta:
verbose_name = "Formulářová stránka" verbose_name = "Formulářová stránka"
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
{% if self.page.root_page.content_is_centered %} {% if self.page.root_page.content_is_centered %}
mx-auto mx-auto
{% else %}
items-center
{% endif %} {% endif %}
" "
action="{% pageurl self.page %}" action="{% pageurl self.page %}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment