Fix multiple inheritance with NewsletterForm. Make phplist URL a setting.
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 10 Sep 2020 09:27:41 +0000 (11:27 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 10 Sep 2020 12:15:11 +0000 (14:15 +0200)
src/club/forms.py
src/newsletter/forms.py
src/newsletter/subscribe.py
src/wolnelektury/settings/custom.py

index 2ebe4e5..d0568c0 100644 (file)
@@ -8,7 +8,7 @@ from . import models
 from .payu.forms import CardTokenForm
 
 
-class ScheduleForm(NewsletterForm, forms.ModelForm):
+class ScheduleForm(forms.ModelForm, NewsletterForm):
     class Meta:
         model = models.Schedule
         fields = ['monthly', 'amount', 'email']
@@ -24,6 +24,10 @@ class ScheduleForm(NewsletterForm, forms.ModelForm):
             raise forms.ValidationError('Minimalna kwota to %d zł.' % club.min_amount)
         return value
 
+    def save(self, *args, **kwargs):
+        NewsletterForm.save(self, *args, **kwargs)
+        return super().save(*args, **kwargs)
+
 
 class PayUCardTokenForm(CardTokenForm):
     def get_queryset(self, view):
index ba086e3..3f08668 100644 (file)
@@ -36,11 +36,6 @@ Więcej informacji w <a href="">polityce prywatności.</a>'''
         if not newsletter:
             return
 
-        try:
-            # multiple inheritance mode
-            super(NewsletterForm, self).save(*args, **kwargs)
-        except AttributeError:
-            pass
         if not (self.mailing or self.cleaned_data.get(self.mailing_field)):
             return
         email = self.cleaned_data[self.email_field]
index d7a8a27..16a27a7 100644 (file)
@@ -2,6 +2,7 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 import requests
+from django.conf import settings
 
 
 def subscribe(email, newsletter):
@@ -13,9 +14,15 @@ def subscribe(email, newsletter):
         "htmlemail": 1,
         "subscribe": "Subscribe",
     }
-    response = requests.post(
-        'https://mailing.mdrn.pl/?p=subscribe',
-        data=data,
-    )
-    response.raise_for_status()
+    if settings.NEWSLETTER_PHPLIST_SUBSCRIBE_URL:
+        response = requests.post(
+            settings.NEWSLETTER_PHPLIST_SUBSCRIBE_URL,
+            data=data,
+        )
+        response.raise_for_status()
+    else:
+        print("Newsletter not configured, "
+            "NEWSLETTER_PHPLIST_SUBSCRIBE_URL not set. "
+            f"Trying to subscribe email: {email} to newsletter: {list_id}."
+        )
 
index 51453ba..8e51f0f 100644 (file)
@@ -44,3 +44,5 @@ AB_TESTS = {
 }
 
 MESSAGING_MIN_DAYS = 2
+
+NEWSLETTER_PHPLIST_SUBSCRIBE_URL = None