From: Radek Czajka Date: Tue, 30 Jun 2020 09:09:57 +0000 (+0200) Subject: Split newsletter forms. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/271208559f072fb43af1b8ac4f3632a10488d283 Split newsletter forms. --- 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, })