email only selected teachers
[edumed.git] / wtem / management / commands / wtem_generate_keys.py
1 # -*- coding: utf-8 -*-
2 from django.core.management.base import BaseCommand
3
4 from wtem.models import Submission, Confirmation
5
6
7 class Command(BaseCommand):
8
9     def handle(self, **options):
10         new = 0
11         skipped = 0
12
13         emails = list(Submission.objects.values_list('email', flat=True))
14         for confirmation in Confirmation.objects.exclude(email__in=emails):
15             if not Submission.objects.filter(email=confirmation.email).exists():
16                 args = {}
17                 for attr in ['first_name', 'last_name', 'email', 'contact']:
18                     args[attr] = getattr(confirmation, attr)
19                 Submission.create(**args)
20                 new += 1
21             else:
22                 self.stdout.write('skipping ' + confirmation.email + ': already exists.')
23                 skipped += 1
24
25         self.stdout.write('New: ' + str(new) + ', skipped: ' + str(skipped))