|
| 1 | +# Copyright The IETF Trust 2016, All Rights Reserved |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +from __future__ import unicode_literals, print_function |
| 4 | + |
| 5 | +import syslog |
| 6 | +import datetime |
| 7 | + |
| 8 | +from django.conf import settings |
| 9 | +from django.core.management.base import BaseCommand |
| 10 | + |
| 11 | +import debug # pyflakes:ignore |
| 12 | + |
| 13 | +from ietf.person.models import Person |
| 14 | +from ietf.utils.mail import send_mail |
| 15 | + |
| 16 | +def log(message): |
| 17 | + syslog.syslog(message) |
| 18 | + |
| 19 | +class Command(BaseCommand): |
| 20 | + help = (u"Send GDPR consent requests to those that need it") |
| 21 | + |
| 22 | + def add_arguments(self, parser): |
| 23 | + parser.add_argument('-n', '--dry-run', dest='dryrun', action='store_true', default=False, |
| 24 | + help="Don't send email, just list recipients") |
| 25 | + |
| 26 | + def handle(self, *args, **options): |
| 27 | + for person in Person.objects.exclude(consent=True): |
| 28 | + fields = ', '.join(person.needs_consent()) |
| 29 | + date = datetime.date.today() + datetime.timedelta(days=30) |
| 30 | + if fields and person.email_set.exists(): |
| 31 | + if options['dryrun']: |
| 32 | + print(("%-32s %-32s %-32s %-32s %s" % (person.email(), person.name_from_draft or '', person.name, person.ascii, fields)).encode('utf8')) |
| 33 | + else: |
| 34 | + to = [ e.address for e in person.email_set.filter(active=True) ] |
| 35 | + if not to: |
| 36 | + to = [ e.address for e in person.email_set.all() ] |
| 37 | + send_mail(None, to, None, |
| 38 | + subject='Personal Information in the IETF Datatracker', |
| 39 | + template='utils/personal_information_notice.txt', |
| 40 | + context={'fields': fields, 'person': person, 'settings': settings, 'date': date, }, ) |
| 41 | + |
0 commit comments