1 from django.core.management.base import BaseCommand, CommandError
3 from contact.models import Contact
4 from wtem.models import Submission
7 class Command(BaseCommand):
9 def handle(self, *ids, **options):
13 query = Contact.objects.filter(form_tag = 'wtem').order_by('-created_at')
15 query = query.filter(pk__in=ids)
17 for wtem_contact in query:
18 for student in wtem_contact.body['student']:
19 if not Submission.objects.filter(email = student['email']).exists():
21 for attr in ['first_name', 'last_name', 'email']:
22 args[attr] = student[attr]
23 args['contact'] = wtem_contact
24 Submission.create(**args)
27 self.stdout.write('skipping ' + student['email'] + ': already exists.')
30 self.stdout.write('New: ' + str(new) + ', skipped: ' + str(skipped))