From 271208559f072fb43af1b8ac4f3632a10488d283 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 30 Jun 2020 11:09:57 +0200 Subject: [PATCH] Split newsletter forms. --- src/newsletter/forms.py | 9 +++------ src/newsletter/templates/newsletter/subscribe_form.html | 1 - src/newsletter/urls.py | 1 + src/newsletter/views.py | 8 ++++---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/newsletter/forms.py b/src/newsletter/forms.py index 1091ed8c2..acf263662 100644 --- a/src/newsletter/forms.py +++ b/src/newsletter/forms.py @@ -52,7 +52,7 @@ Więcej informacji w polityce prywatności.''' # send_noreply_mail( # ugettext('Confirm your subscription to Wolne Lektury newsletter'), # render_to_string('newsletter/subscribe_email.html', {'subscription': subscription}), [email]) - mailing.subscribe(email, mailing_lists=self.cleaned_data.get('mailing_lists')) + mailing.subscribe(email, mailing_lists=[self.mailing_list]) class SubscribeForm(NewsletterForm): @@ -60,12 +60,9 @@ class SubscribeForm(NewsletterForm): agree_newsletter = None email = EmailField(label=_('email address')) - mailing_lists = MultipleChoiceField( - widget=CheckboxSelectMultiple, - choices=(('general', _('general newsletter')), ('contest', _('about the contest'))), - label=_('mailing list')) - def __init__(self, *args, **kwargs): + def __init__(self, mailing_list, *args, **kwargs): + self.mailing_list = mailing_list super(SubscribeForm, self).__init__(*args, **kwargs) diff --git a/src/newsletter/templates/newsletter/subscribe_form.html b/src/newsletter/templates/newsletter/subscribe_form.html index 53d79010a..6d9f3bc90 100644 --- a/src/newsletter/templates/newsletter/subscribe_form.html +++ b/src/newsletter/templates/newsletter/subscribe_form.html @@ -10,7 +10,6 @@ {% render_honeypot_field %}
  1. {{ form.email|pretty_field }}
  2. -
  3. {{ form.mailing_lists|pretty_field }}
  4. {{ form.data_processing }}
diff --git a/src/newsletter/urls.py b/src/newsletter/urls.py index bfae579a4..290bb87a5 100644 --- a/src/newsletter/urls.py +++ b/src/newsletter/urls.py @@ -6,6 +6,7 @@ from . import views urlpatterns = [ path('zapisz-sie/', views.subscribe_form, name='subscribe'), + path('zapisz-sie/konkurs/', views.subscribe_form, {"title": "Zapisz się na newsletter Konkursu", "mailing_list": "contest"}, name='subscribe-contest'), path('zapis/', views.subscribed, name='subscribed'), path('potwierdzenie///', views.confirm_subscription, name='confirm_subscription'), diff --git a/src/newsletter/views.py b/src/newsletter/views.py index 4c57a251d..6c90873bb 100644 --- a/src/newsletter/views.py +++ b/src/newsletter/views.py @@ -11,16 +11,16 @@ from newsletter.forms import UnsubscribeForm, SubscribeForm from newsletter.models import Subscription -def subscribe_form(request): +def subscribe_form(request, mailing_list='general', title=None): if request.POST: - form = SubscribeForm(request.POST) + form = SubscribeForm(mailing_list, request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('subscribed')) else: - form = SubscribeForm() + form = SubscribeForm(mailing_list) return render(request, 'newsletter/subscribe_form.html', { - 'page_title': _('Subscribe To Newsletter'), + 'page_title': title or _('Subscribe To Newsletter'), 'form': form, }) -- 2.20.1