hook mailchimp to contact forms
[edumed.git] / contact / management / commands / export_newsletter.py
1 # -*- coding: utf-8 -*-
2 # This file is part of EduMed, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django.core.management.base import BaseCommand
6
7 from contact.models import Contact
8 from edumed import contact_forms
9
10 FORMS = (
11     contact_forms.OlimpiadaForm,
12 )
13
14
15 class Command(BaseCommand):
16     help = 'Export contacts for newsletter.'
17
18     def handle(self, **options):
19         addresses = set(self.get_addresses())
20         for address in addresses:
21             print address
22
23     def get_addresses(self):
24         for form in FORMS:
25             tags = [form.form_tag] + form.old_form_tags
26             contacts = Contact.objects.filter(form_tag__in=tags)
27             for contact in contacts:
28                 if contact.body.get(form.mailing_field):
29                     yield contact.contact