Login form.
[wolnelektury.git] / src / newsletter / views.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django.http.response import HttpResponseRedirect
5 from django.shortcuts import render, get_object_or_404
6 from django.urls import reverse
7 from django.utils.translation import gettext_lazy as _
8
9 from newsletter.forms import SubscribeForm, Newsletter
10
11
12 def subscribe_form(request, slug=''):
13     newsletter = get_object_or_404(Newsletter, slug=slug)
14     new_layout = request.EXPERIMENTS['layout'].value
15     if request.POST:
16         form = SubscribeForm(newsletter, request.POST)
17         if form.is_valid():
18             form.save()
19             return HttpResponseRedirect(reverse('subscribed'))
20     else:
21         form = SubscribeForm(newsletter)
22
23     if new_layout:
24         template_name = 'newsletter/2022/subscribe_form.html'
25         form.template_name = '2022/form.html'
26     else:
27         template_name = 'newsletter/subscribe_form.html'
28     return render(request, template_name, {
29         'page_title': newsletter.page_title,
30         'form': form,
31     })
32
33
34 def subscribed(request):
35     new_layout = request.EXPERIMENTS['layout'].value
36     if new_layout:
37         template_name = 'newsletter/2022/subscribed.html'
38     else:
39         template_name = 'newsletter/subscribed.html'
40     return render(request, template_name, {
41         'page_title': _('Subscribed'),
42     })
43