Update email template
[edumed.git] / wtem / management / commands / wtem_generate_keys.py
1 from django.core.management.base import BaseCommand, CommandError
2
3 from contact.models import Contact
4 from wtem.models import Submission
5
6
7 class Command(BaseCommand):
8     
9     def handle(self, *args, **options):
10         new = 0
11         skipped = 0
12
13         for wtem_contact in Contact.objects.filter(form_tag = 'wtem'):
14             for student in wtem_contact.body['student']:
15                 if not Submission.objects.filter(email = student['email']).exists():
16                     args = dict()
17                     for attr in ['first_name', 'last_name', 'email']:
18                         args[attr] = student[attr]
19                     args['contact'] = wtem_contact
20                     Submission.create(**args)
21                     new += 1
22                 else:
23                     self.stdout.write('skipping ' + student['email'] + ': already exists.')
24                     skipped += 1
25
26         self.stdout.write('New: ' + str(new) + ', skipped: ' + str(skipped))