1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
5 from django.conf import settings
6 from club.civicrm import civicrm
9 def subscribe(email, newsletter):
11 subscribe_crm(email, newsletter.crm_id)
12 if newsletter.phplist_id:
13 subscribe_phplist(email, newsletter.phplist_id)
15 def subscribe_crm(email, group_id):
16 civicrm.add_email_to_group(email, group_id)
18 def subscribe_phplist(email, list_id):
21 "emailconfirm": email,
22 f"list[{list_id}]": "signup",
24 "subscribe": "Subscribe",
26 if settings.NEWSLETTER_PHPLIST_SUBSCRIBE_URL:
27 response = requests.post(
28 settings.NEWSLETTER_PHPLIST_SUBSCRIBE_URL,
31 response.raise_for_status()
33 print("Newsletter not configured, "
34 "NEWSLETTER_PHPLIST_SUBSCRIBE_URL not set. "
35 f"Trying to subscribe email: {email} to newsletter: {list_id}."