diff --git a/elections2021/forms.py b/elections2021/forms.py index 2743ffd0a8e1b2d58295c307830ee886498b3599..cf14770f6c2ff65e3191a197a92b8a4ec1fbba44 100644 --- a/elections2021/forms.py +++ b/elections2021/forms.py @@ -87,3 +87,9 @@ class ProgramAppForm(forms.Form): choices=OCCUPATION_CHOICES, initial=OCCUPATION_WORKING ) topics = forms.MultipleChoiceField(required=False, choices=TOPIC_CHOICES) + + +class SubscribeForm(forms.Form): + email = forms.EmailField() + confirmed = forms.BooleanField() + return_page_id = forms.IntegerField() diff --git a/elections2021/models.py b/elections2021/models.py index b5bece09d264700b05c76b4e6bce6fe3df48c6db..e8b4e0fc7693ed88040c1d2c7a2bf861b058928a 100644 --- a/elections2021/models.py +++ b/elections2021/models.py @@ -33,7 +33,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin from shared.models import ArticleMixin, SubpageMixin -from shared.utils import get_subpage_url +from shared.utils import get_subpage_url, subscribe_to_newsletter from tuning import help from .constants import ( @@ -106,7 +106,7 @@ from .constants import ( WHITE, WORKING_SENIORS, ) -from .forms import ProgramAppForm, ProgramPointPageForm +from .forms import ProgramAppForm, ProgramPointPageForm, SubscribeForm from .utils import get_archetype NO_SEARCH_IMAGE_USE_PHOTO = ( @@ -174,7 +174,7 @@ class SlideBlock(blocks.StructBlock): template = "elections2021/_carousel_slide.html" -class Elections2021HomePage(Page, MetadataPageMixin): +class Elections2021HomePage(MetadataPageMixin, RoutablePageMixin, Page): ### FIELDS carousel = StreamField( @@ -348,6 +348,10 @@ class Elections2021HomePage(Page, MetadataPageMixin): return self.program_strategic_page.url return "#" + @cached_property + def newsletter_subscribe_url(self): + return self.url + self.reverse_subpage("newsletter_subscribe") + def get_context(self, request): context = super().get_context(request) context["articles"] = ( @@ -368,6 +372,27 @@ class Elections2021HomePage(Page, MetadataPageMixin): context["countdown_hours"] = int(hours) return context + @route(r"^prihlaseni-k-newsletteru/$") + def newsletter_subscribe(self, request): + if request.method == "POST": + form = SubscribeForm(request.POST) + if form.is_valid(): + subscribe_to_newsletter( + form.cleaned_data["email"], + settings.ELECTIONS2021_NEWSLETTER_ID, + settings.ELECTIONS2021_NEWSLETTER_SOURCE, + ) + try: + page = ( + Page.objects.filter(id=form.cleaned_data["return_page_id"]) + .live() + .first() + ) + return HttpResponseRedirect(page.full_url) + except Page.DoesNotExist: + return HttpResponseRedirect(self.url) + return HttpResponseRedirect(self.url) + class Elections2021ArticleTag(TaggedItemBase): content_object = ParentalKey( @@ -1132,7 +1157,7 @@ class Elections2021ProgramPage( return self.url + self.reverse_subpage("my_program") @route(r"^$") - def plan_all(self, request, param=None): + def plan_all(self, request): points = Elections2021ProgramPointPage.objects.live().specific() points = Paginator(points, PROGRAM_POINTS_PER_PAGE).get_page( request.GET.get("page") diff --git a/elections2021/templates/elections2021/_side_panel.html b/elections2021/templates/elections2021/_side_panel.html index 6d803a7298678526763ea976ca218e3e0d636ab6..ba0a74b9113b1e4899b4884c79d2e999789f5f9a 100644 --- a/elections2021/templates/elections2021/_side_panel.html +++ b/elections2021/templates/elections2021/_side_panel.html @@ -4,10 +4,11 @@ <div class="cta-card cta-news px-8 py-8 bg-acidgreen sidePanel"> <p class="font-alt text-4xl">CHCI VĚDĚT VÍCE</p> - <form method="post"> + <form method="post" action="{{ page.root_page.newsletter_subscribe_url }}"> {% csrf_token %} - <input name="" type="email" class="text-input form-field__control w-full mt-7" value="" placeholder="Zadejte email" required=""> - <button class="btn btn--icon my-2 text-lg w-full cta-btn" disabled=""> + <input type="hidden" name="return_page_id" value="{{ page.id }}"> + <input name="email" type="email" class="text-input form-field__control w-full mt-7" value="" placeholder="Zadejte email" required=""> + <button class="btn btn--icon my-2 text-lg w-full cta-btn"> <div class="btn__body-wrap"> <div class="btn__body py-4 leading-4 w-full">Přihlásit se k newsletteru</div> <div class="btn__icon px-4 bg-grey-800 border-grey-500"> @@ -16,8 +17,8 @@ </div> </button> <div class="checkbox form-field__control cta-cbox h-6"> - <input type="checkbox" id="checkbox_1" required=""> - <label for="checkbox_1" style="color: #000000"> Souhlasím se <a href="{{ page.root_page.gdpr_and_cookies_url }}" target="_blank">zásadami ochrany osobních údajů</a> a zasíláním novinek</label> + <input type="checkbox" name="confirmed" id="confirmed" required=""> + <label for="confirmed" style="color: #000000"> Souhlasím se <a href="{{ page.root_page.gdpr_and_cookies_url }}" target="_blank">zásadami ochrany osobních údajů</a> a zasíláním novinek</label> </div> </form> </div> diff --git a/elections2021/templates/elections2021/elections2021_home_page.html b/elections2021/templates/elections2021/elections2021_home_page.html index 10560301771fae78c9e19e047db319bff78fe2e3..4828a1d1a4707e02ebccd1036bf114f39b1322b3 100644 --- a/elections2021/templates/elections2021/elections2021_home_page.html +++ b/elections2021/templates/elections2021/elections2021_home_page.html @@ -140,10 +140,11 @@ <div class="w-full"> <div class="cta-card cta-news px-8 py-8 bg-acidgreen text-black"> <p class="font-alt text-4xl">CHCI VĚDĚT VÍCE</p> - <form method="post"> + <form method="post" action="{{ page.root_page.newsletter_subscribe_url }}"> {% csrf_token %} - <input name="" type="email" class="text-input form-field__control w-full mt-7" value="" placeholder="Zadejte email" required=""> - <button class="btn btn--icon my-2 text-lg w-full cta-btn" disabled=""> + <input type="hidden" name="return_page_id" value="{{ page.id }}"> + <input name="email" type="email" class="text-input form-field__control w-full mt-7" value="" placeholder="Zadejte email" required=""> + <button class="btn btn--icon my-2 text-lg w-full cta-btn"> <div class="btn__body-wrap"> <div class="btn__body py-4 leading-4 w-full">Přihlásit se k newsletteru</div> <div class="btn__icon px-4 bg-grey-800 border-grey-500"> @@ -152,8 +153,8 @@ </div> </button> <div class="checkbox form-field__control cta-cbox h-6"> - <input type="checkbox" id="checkbox_1" required=""> - <label for="checkbox_1" style="color: #000000"> Souhlasím se <a href="{{ page.root_page.gdpr_and_cookies_url }}" target="_blank">zásadami ochrany osobních údajů</a> a zasíláním novinek</label> + <input type="checkbox" name="confirmed" id="confirmed_bottom" required=""> + <label for="confirmed_bottom" style="color: #000000"> Souhlasím se <a href="{{ page.root_page.gdpr_and_cookies_url }}" target="_blank">zásadami ochrany osobních údajů</a> a zasíláním novinek</label> </div> </form> </div> diff --git a/elections2021/templates/elections2021/elections2021_program_point_page.html b/elections2021/templates/elections2021/elections2021_program_point_page.html index 013304041e8fef7d63404d8eaa7d0baee8efde9d..41ef872e6ded86d4540c007cad4fb66440226cb7 100644 --- a/elections2021/templates/elections2021/elections2021_program_point_page.html +++ b/elections2021/templates/elections2021/elections2021_program_point_page.html @@ -21,7 +21,7 @@ <li><a href="#pro-koho-to-chceme-hlavne">Pro koho to chceme hlavně</a></li> {% endif %} <li><a href="#co-pro-to-uz-delame">Co pro to už děláme</a></li> - <li><a href="#na-co-se-nas-casto-ptate">Na co se nás často ptát</a></li> + <li><a href="#na-co-se-nas-casto-ptate">Na co se nás často ptáte</a></li> <li><a href="#zdroje">Klidně si to ověřte</a></li> </ul> </div>