Split newsletter forms.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 30 Jun 2020 09:09:57 +0000 (11:09 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 10 Sep 2020 12:15:11 +0000 (14:15 +0200)
src/newsletter/forms.py
src/newsletter/templates/newsletter/subscribe_form.html
src/newsletter/urls.py
src/newsletter/views.py

index 1091ed8..acf2636 100644 (file)
@@ -52,7 +52,7 @@ Więcej informacji w <a href="">polityce prywatności.</a>'''
             # 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)
 
 
index 53d7901..6d9f3bc 100644 (file)
@@ -10,7 +10,6 @@
     {% render_honeypot_field %}
     <ol>
       <li>{{ form.email|pretty_field }}</li>
-      <li>{{ form.mailing_lists|pretty_field }}</li>
       <li><span class="helptext">{{ form.data_processing }}</span></li>
       <li><input type="submit" value="{% trans "Subscribe" %}"/></li>
     </ol>
index bfae579..290bb87 100644 (file)
@@ -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/<int:subscription_id>/<slug:hashcode>/',
         views.confirm_subscription, name='confirm_subscription'),
index 4c57a25..6c90873 100644 (file)
@@ -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,
     })