mirror of https://github.com/fspc/workstand.git
Drew Larson
8 years ago
committed by
GitHub
12 changed files with 115 additions and 13 deletions
@ -0,0 +1 @@ |
|||
default_app_config = 'registration.apps.RegistrationConfig' |
@ -0,0 +1,30 @@ |
|||
import hashlib |
|||
|
|||
from django.db.models.signals import post_save |
|||
from django.dispatch import receiver |
|||
from django.conf import settings |
|||
from mailchimp3 import MailChimp |
|||
from requests import HTTPError |
|||
|
|||
from registration.models import Member |
|||
|
|||
|
|||
@receiver(post_save, sender=Member, dispatch_uid='member.save_member') |
|||
def update_mailchimp(sender, instance, **kwargs): |
|||
if instance.email: |
|||
involvement = {id: True for id in instance.involvement} |
|||
client = MailChimp(settings.MAILCHIMP_USERNAME, settings.MAILCHIMP_API_KEY) |
|||
try: |
|||
response = client.lists.members.create_or_update('1c664549e2', |
|||
hashlib.md5(bytes(instance.email, 'utf-8')).hexdigest(), { |
|||
'email_address': instance.email, |
|||
'status': 'subscribed' if instance.email_consent else 'unsuscribed', |
|||
'status_if_new': 'subscribed' if instance.email_consent else 'unsuscribed', |
|||
'merge_fields': { |
|||
'FNAME': instance.first_name, |
|||
'LNAME': instance.last_name, |
|||
}, |
|||
'interests': involvement |
|||
}) |
|||
except HTTPError as error: |
|||
pass |
@ -0,0 +1,28 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.4 on 2017-05-28 23:39 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.conf import settings |
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
import multiselectfield.db.fields |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('registration', '0004_auto_20170518_0332'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='member', |
|||
name='involvement', |
|||
field=multiselectfield.db.fields.MultiSelectField(blank=True, choices=[('ac6922146d', 'General (receive email)'), ('3a5a719017', 'Volunteering'), ('0ebb0b5468', 'Events'), ('84309225e7', 'Workshops'), ('c96d389517', 'Shop')], max_length=54, null=True), |
|||
), |
|||
migrations.AlterField( |
|||
model_name='member', |
|||
name='user', |
|||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), |
|||
), |
|||
] |
Loading…
Reference in new issue