From: Jan Szejko Date: Fri, 14 Oct 2016 14:49:43 +0000 (+0200) Subject: wlem keys X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/9ff76cf1dc687baafbe04acc4aa8f545decb64c4 wlem keys --- diff --git a/wtem/management/commands/wlem_generate_keys.py b/wtem/management/commands/wlem_generate_keys.py new file mode 100644 index 0000000..3fbf107 --- /dev/null +++ b/wtem/management/commands/wlem_generate_keys.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from django.core.management.base import BaseCommand + +from contact.models import Contact +from wtem.models import Submission + + +class Command(BaseCommand): + + def handle(self, *ids, **options): + new = 0 + skipped = 0 + + query = Contact.objects.filter(form_tag='wlem').order_by('-created_at') + if ids: + query = query.filter(pk__in=ids) + + for wlem_contact in query: + if not Submission.objects.filter(email=wlem_contact.contact).exists(): + first_name, last_name = wlem_contact.body['nazwisko'].split(' ') + args = { + 'email': wlem_contact.contact, + 'first_name': first_name, + 'last_name': last_name, + } + Submission.create(**args) + new += 1 + else: + self.stdout.write('skipping ' + wlem_contact.contact + ': already exists.') + skipped += 1 + + self.stdout.write('New: ' + str(new) + ', skipped: ' + str(skipped)) diff --git a/wtem/management/commands/wtem_send_keys.py b/wtem/management/commands/wtem_send_keys.py index 213f992..96511fb 100644 --- a/wtem/management/commands/wtem_send_keys.py +++ b/wtem/management/commands/wtem_send_keys.py @@ -64,6 +64,6 @@ class Command(BaseCommand): def send_key(self, submission): self.stdout.write('>>> sending to ' + submission.email) send_mail( - subject="WTEM - Twój link do zadań", + subject="WLEM - Twój link do egzaminu", body=render_to_string('wtem/email_key.txt', dict(submission=submission)), to=[submission.email])