update emails for stage2
[edumed.git] / wtem / management / commands / wlem_generate_keys.py
1 # -*- coding: utf-8 -*-
2 from django.core.management.base import BaseCommand
3
4 from contact.models import Contact
5 from wtem.models import Submission
6
7
8 class Command(BaseCommand):
9
10     def handle(self, *ids, **options):
11         return  # typo would be disastrous
12         new = 0
13         skipped = 0
14
15         query = Contact.objects.filter(form_tag='wlem').order_by('-created_at')
16         if ids:
17             query = query.filter(pk__in=ids)
18
19         for wlem_contact in query:
20             if not Submission.objects.filter(email=wlem_contact.contact).exists():
21                 first_name, last_name = wlem_contact.body['nazwisko'].split()
22                 args = {
23                     'email': wlem_contact.contact,
24                     'first_name': first_name,
25                     'last_name': last_name,
26                 }
27                 Submission.create(**args)
28                 new += 1
29             else:
30                 self.stdout.write('skipping ' + wlem_contact.contact + ': already exists.')
31                 skipped += 1
32
33         self.stdout.write('New: ' + str(new) + ', skipped: ' + str(skipped))