From 88bfac93513a532bdbd0311a84a62ab854e473cc Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 10 Sep 2020 11:27:41 +0200 Subject: [PATCH] Fix multiple inheritance with NewsletterForm. Make phplist URL a setting. --- src/club/forms.py | 6 +++++- src/newsletter/forms.py | 5 ----- src/newsletter/subscribe.py | 17 ++++++++++++----- src/wolnelektury/settings/custom.py | 2 ++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/club/forms.py b/src/club/forms.py index 2ebe4e58d..d0568c023 100644 --- a/src/club/forms.py +++ b/src/club/forms.py @@ -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): diff --git a/src/newsletter/forms.py b/src/newsletter/forms.py index ba086e352..3f08668ea 100644 --- a/src/newsletter/forms.py +++ b/src/newsletter/forms.py @@ -36,11 +36,6 @@ Więcej informacji w polityce prywatności.''' 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] diff --git a/src/newsletter/subscribe.py b/src/newsletter/subscribe.py index d7a8a2795..16a27a793 100644 --- a/src/newsletter/subscribe.py +++ b/src/newsletter/subscribe.py @@ -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}." + ) diff --git a/src/wolnelektury/settings/custom.py b/src/wolnelektury/settings/custom.py index 51453baca..8e51f0fdb 100644 --- a/src/wolnelektury/settings/custom.py +++ b/src/wolnelektury/settings/custom.py @@ -44,3 +44,5 @@ AB_TESTS = { } MESSAGING_MIN_DAYS = 2 + +NEWSLETTER_PHPLIST_SUBSCRIBE_URL = None -- 2.20.1