X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/64d26c022dc182339b33c3cd8e4ef1978b150573..c36c3891e56611e2ad4c518daa46b8cc3f28188e:/src/newsletter/subscribe.py diff --git a/src/newsletter/subscribe.py b/src/newsletter/subscribe.py index d7a8a2795..dc3445fce 100644 --- a/src/newsletter/subscribe.py +++ b/src/newsletter/subscribe.py @@ -1,11 +1,21 @@ -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # import requests +from django.conf import settings +from club.civicrm import civicrm def subscribe(email, newsletter): - list_id = newsletter.phplist_id + if newsletter.crm_id: + subscribe_crm(email, newsletter.crm_id) + if newsletter.phplist_id: + subscribe_phplist(email, newsletter.phplist_id) + +def subscribe_crm(email, group_id): + civicrm.add_email_to_group(email, group_id) + +def subscribe_phplist(email, list_id): data = { "email": email, "emailconfirm": email, @@ -13,9 +23,14 @@ 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}." + )