ref(newsletter): Customise le fonctionnement de birdsong pour travailler avec Sympa
+ migrations initialespull/48/head
Parent
90474acf48
révision
b27c4747cf
|
@ -10,4 +10,4 @@ django-tapeforms >=1.1,<1.2 # https://github.com/stephrdev/django-tapeforms
|
|||
# ------------------------------------------------------------------------------
|
||||
wagtail >=2.15,<2.16
|
||||
wagtail-cblocks >=0.3,<0.4
|
||||
wagtail-birdsong >=1.0,<1.1
|
||||
wagtail-birdsong >=1.1,<1.2
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.2.16 on 2022-11-09 09:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0019_alter_sitesettings_main_menu'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='sitesettings',
|
||||
name='newsletter_link',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='formfield',
|
||||
name='field_type',
|
||||
field=models.CharField(choices=[('singleline', 'Single line text'), ('multiline', 'Multi-line text'), ('email', 'Email'), ('number', 'Number'), ('url', 'URL'), ('checkbox', 'Checkbox'), ('checkboxes', 'Checkboxes'), ('dropdown', 'Drop down'), ('multiselect', 'Multiple select'), ('radio', 'Radio buttons'), ('date', 'Date'), ('datetime', 'Date/time'), ('hidden', 'Hidden field'), ('is_robot', 'Case à laisser vide pour tromper les robots'), ('is_human', 'Case à cocher par les humains')], max_length=16, verbose_name='type de champ'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,47 @@
|
|||
from django.conf import settings
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from birdsong.backends import BaseEmailBackend
|
||||
from birdsong.backends.smtp import SendCampaignThread
|
||||
from birdsong.utils import send_mass_html_mail
|
||||
|
||||
DEFAULT_MAILING_LIST = ''
|
||||
|
||||
|
||||
class SympaListEmailBackend(BaseEmailBackend):
|
||||
"""
|
||||
Custom backend class to smoothen the association between Birdsong and
|
||||
Sympa, respectively for editing campaigns/managing contacts, and
|
||||
sending them.
|
||||
"""
|
||||
|
||||
def send_campaign(self, request, campaign, contacts, test_send=False):
|
||||
content = render_to_string(
|
||||
campaign.get_template(request),
|
||||
# empty string because contact does not matter in our case
|
||||
campaign.get_context(request, ''),
|
||||
)
|
||||
# message remains a list not to break SendCampaignThread behavior
|
||||
message = [
|
||||
{
|
||||
'subject': campaign.subject,
|
||||
'body': content,
|
||||
'from_email': self.from_email,
|
||||
'to': [
|
||||
getattr(
|
||||
settings,
|
||||
'NEWSLETTER_MAILING_LIST',
|
||||
DEFAULT_MAILING_LIST,
|
||||
)
|
||||
],
|
||||
}
|
||||
]
|
||||
if test_send:
|
||||
# In this case contacts is a list containing a single contact
|
||||
# message's 'to' field is then replaced by the contact's email
|
||||
message[0]['to'] = [contact.email for contact in contacts]
|
||||
send_mass_html_mail(message)
|
||||
else:
|
||||
# empty contacts list because it is irrelevant in our case
|
||||
campaign_thread = SendCampaignThread(campaign.pk, [], message)
|
||||
campaign_thread.start()
|
Diff de fichier supprimé car une ou plusieurs lignes sont trop longues
|
@ -63,6 +63,12 @@ class Newsletter(Campaign):
|
|||
StreamFieldPanel('body'),
|
||||
]
|
||||
|
||||
def get_context(self, request, contacts=''):
|
||||
# Contacts are no longer useful in context given only one email
|
||||
# is generated and then sent to a list
|
||||
context = super().get_context(request, '')
|
||||
context['root_url'] = Site.objects.get(is_default_site=True).root_url
|
||||
return context
|
||||
|
||||
class UniqueContact(Contact):
|
||||
"""
|
||||
|
|
|
@ -304,3 +304,9 @@ MJML_EXEC_CMD = [
|
|||
'--config.validationLevel',
|
||||
'strict',
|
||||
]
|
||||
|
||||
# Birdsong
|
||||
# ------------------------------------------------------------------------------
|
||||
BIRDSONG_BACKEND = 'toitcommun_site.newsletter.backend.SympaListEmailBackend'
|
||||
|
||||
NEWSLETTER_MAILING_LIST = 'newsletter@listes.letoitcommun.org'
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
<mj-section background-color="white">
|
||||
<mj-column>
|
||||
<mj-text align="center">
|
||||
Cliquez <a href="{{ site.full_url }}{% url 'newsletter:unsubscribe' contact.id %}">ici</a> pour vous désinscrire.
|
||||
Cliquez <a href="{{ site.full_url }}">ici</a> pour vous désinscrire.
|
||||
</mj-text>
|
||||
</mj-column>
|
||||
</mj-section>
|
||||
|
|
Chargement…
Référencer dans un nouveau ticket