X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/ba913c828671f5c896e2c3d718cc18225955b86d..2d5e46793f9b1f3f87f972114a4448da8efe740e:/contact/management/commands/export_newsletter.py?ds=sidebyside diff --git a/contact/management/commands/export_newsletter.py b/contact/management/commands/export_newsletter.py new file mode 100644 index 0000000..43b35ee --- /dev/null +++ b/contact/management/commands/export_newsletter.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# This file is part of EduMed, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from django.core.management.base import BaseCommand + +from contact.models import Contact +from edumed import contact_forms + +FORMS = ( + contact_forms.OlimpiadaForm, +) + + +class Command(BaseCommand): + help = 'Export contacts for newsletter.' + + def handle(self, **options): + addresses = set(self.get_addresses()) + for address in addresses: + print address + + def get_addresses(self): + for form in FORMS: + tags = [form.form_tag] + form.old_form_tags + contacts = Contact.objects.filter(form_tag__in=tags) + for contact in contacts: + if contact.body.get(form.mailing_field): + yield contact.contact