1 # -*- coding: utf-8 -*-
2 from django.core.management.base import BaseCommand
4 from contact.models import Contact
5 from wtem.models import Submission
8 class Command(BaseCommand):
10 def handle(self, *ids, **options):
14 query = Contact.objects.filter(form_tag='olimpiada').order_by('-created_at')
16 query = query.filter(pk__in=ids)
18 for wtem_contact in query:
19 for student in wtem_contact.body['student']:
20 if not Submission.objects.filter(email=student['email']).exists():
22 for attr in ['first_name', 'last_name', 'email']:
23 args[attr] = student[attr]
24 args['contact'] = wtem_contact
25 Submission.create(**args)
28 self.stdout.write('skipping ' + student['email'] + ': already exists.')
31 self.stdout.write('New: ' + str(new) + ', skipped: ' + str(skipped))