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

czech inspirational: Download and news subscribe

parent ae3f986c
No related branches found
No related tags found
2 merge requests!212czech inspirational: Download and news subscribe,!211czech inspirational: Download and news subscribe
Pipeline #3182 passed
import json
import logging
import requests
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.db import models
from django.utils.translation import gettext_lazy
from wagtail.admin.edit_handlers import FieldPanel, HelpPanel, MultiFieldPanel
......@@ -11,6 +18,8 @@ from shared.models import SubpageMixin
from tuning import help
from uniweb.constants import RICH_TEXT_FEATURES
logger = logging.getLogger()
class CzechInspirationalHomePage(Page, MetadataPageMixin):
### FIELDS
......@@ -249,3 +258,40 @@ class CzechInspirationalDownloadPage(Page, SubpageMixin, MetadataPageMixin):
class Meta:
verbose_name = "Download"
def get_context(self, request):
context = super().get_context(request)
if "stahnout" in request.GET:
context["show"] = "download"
elif "diky" in request.GET:
context["show"] = "thanks"
else:
context["show"] = "info"
if "email" in request.POST:
context["show"] = "download"
if "subscribe" in request.POST:
email = request.POST.get("email", "")
try:
validate_email(email)
except ValidationError:
pass
else:
payload = {
"email": email,
"news_id": settings.CZECH_INSPIRATIONAL_NEWSLETTER_ID,
}
response = requests.post(
settings.NALODENI_API_NEWS_SUBSCRIBE_URL,
data=json.dumps(payload),
auth=tuple(settings.NALODENI_API_CREDENTIALS.split(":")),
)
if response.status_code != 200:
logger.error(
"Failed to subscribe!",
extra={"email": email, "response": response.text},
)
return context
......@@ -4,31 +4,56 @@
{% block content %}
<div class="container container--default">
<h2 id="downloadheading" class="mt-40 mx-auto mb-8 --leading-4 head-alt-md lg:head-alt-lg max-w-xl text-center">Zadejte svůj e-mail a&nbsp;stáhněte si ebook</h2>
<form id="savemailform" class="text-center block">
<div class="inline-block text-left align-top">
<input type="email" name="email" class="text-input form-field__control w-full" value="" placeholder="Váš Email" required="">
<div class="checkbox form-field__control display-block mt-2 mb-8 md:mb-0">
<input type="checkbox" id="checkbox_1" required="">
<label for="checkbox_1">Souhlasím se zásadami ochrany osobních údajů</label>
{% if show == "download" %}
<h2 id="downloadheading" class="mt-40 mx-auto mb-8 --leading-4 head-alt-md lg:head-alt-lg max-w-xl text-center">Příjemné<br>čtení!</h2>
<div class="text-center pb-2 md:pb-0 mb-28">
<a class="dlhref md:mx-4" href="{{ page.book_file.url }}">
<button class="w-80 text-lg btn btn--hoveractive btn--to-grey-700 inline-block align-top mb-3">
<div class="btn__body py-10 h-12">Stáhnout ebook</div>
</button>
</a>
</div>
<div class="checkbox form-field__control display-block mt-2 mb-8 md:mb-0">
<input type="checkbox" id="checkbox_2">
<label for="checkbox_2">Souhlasím se zasíláním novinek od Pirátské strany</label>
{% elif show == "thanks" %}
<h2 id="downloadheading" class="mt-40 mx-auto mb-46 --leading-4 head-alt-md lg:head-alt-lg max-w-xl text-center">Kniha se stahuje,<br>děkujeme</h2>
<div class="mt-64 pt-8 sm:pt-0 sm:mt-48 text-center">
<a href="/" class="head-heavy-2xs underline text-cyan-200 whitespace-nowrap"><span class="head-heavy-2xs">Zpět na Homepage</span></a>
</div>
</div>
<button class="mt-0 btn text-lg btn btn--cyan-200 btn--hoveractive border-cyan-200 inline-block align-top" disabled="disabled">
<div class="btn__body py-0 h-12">Potvrdit</div>
</button>
<div class="mt-12 pt-1 text-center">
<a id="nomail" href="{{ page.book_file.url }}" class="head-heavy-2xs underline text-cyan-200 whitespace-nowrap">
<span href="#" class="social-icon social-icon--fill social-icon--4 bg-cyan-200 text-white mr-2">
<i class="ico--download3 text-sm"></i>
</span>
<span class="head-heavy-2xs">Chci stáhnout ebook bez zadání emailu</span>
</a>
</div>
</form>
{% else %}
<h2 id="downloadheading" class="mt-40 mx-auto mb-8 --leading-4 head-alt-md lg:head-alt-lg max-w-xl text-center">Zadejte svůj e-mail a&nbsp;stáhněte si ebook</h2>
<form class="text-center block" method="post">
{% csrf_token %}
<div class="inline-block text-left align-top">
<input type="email" name="email" class="text-input form-field__control w-full" value="" placeholder="Váš Email" required="required">
<div class="checkbox form-field__control display-block mt-2 mb-8 md:mb-0">
<input type="checkbox" id="checkbox_1" required="required" name="accept_terms">
<label for="checkbox_1">Souhlasím se zásadami ochrany osobních údajů</label>
</div>
<div class="checkbox form-field__control display-block mt-2 mb-8 md:mb-0">
<input type="checkbox" id="checkbox_2" name="subscribe">
<label for="checkbox_2">Souhlasím se zasíláním novinek od Pirátské strany</label>
</div>
</div>
<button class="mt-0 btn text-lg btn btn--cyan-200 btn--hoveractive border-cyan-200 inline-block align-top">
<div class="btn__body py-0 h-12">Potvrdit</div>
</button>
<div class="mt-12 pt-1 text-center">
<a href="?stahnout" class="head-heavy-2xs underline text-cyan-200 whitespace-nowrap">
<span href="#" class="social-icon social-icon--fill social-icon--4 bg-cyan-200 text-white mr-2">
<i class="ico--download3 text-sm"></i>
</span>
<span class="head-heavy-2xs">Chci stáhnout ebook bez zadání emailu</span>
</a>
</div>
</form>
{% endif %}
</div>
<div class="text-center mb-20">
......
......@@ -249,3 +249,9 @@ DONATE_PORTAL_REDIRECT_SOURCE = env.str(
DONATE_PORTAL_API_URL = env.str("DONATE_PORTAL_API_URL", default="")
DONATE_PORTAL_API_TIMEOUT = 5
DONATE_PORTAL_API_CACHE_TIMEOUT = 60 * 5
CZECH_INSPIRATIONAL_NEWSLETTER_ID = env.int(
"CZECH_INSPIRATIONAL_NEWSLETTER_ID", default=0
)
NALODENI_API_NEWS_SUBSCRIBE_URL = env.str("NALODENI_API_NEWS_SUBSCRIBE_URL", default="")
NALODENI_API_CREDENTIALS = env.str("NALODENI_API_CREDENTIALS", default="")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment