fix for toc events
[wolnelektury.git] / src / newsletter / views.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. 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 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     if request.POST:
15         form = SubscribeForm(newsletter, request.POST)
16         if form.is_valid():
17             form.save()
18             return HttpResponseRedirect(reverse('subscribed'))
19     else:
20         form = SubscribeForm(newsletter)
21
22     template_name = 'newsletter/subscribe_form.html'
23     return render(request, template_name, {
24         'page_title': newsletter.page_title,
25         'form': form,
26     })
27
28
29 def subscribed(request):
30     template_name = 'newsletter/subscribed.html'
31     return render(request, template_name, {
32         'page_title': _('Zapisano do newslettera'),
33     })
34