From 9ff76cf1dc687baafbe04acc4aa8f545decb64c4 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Fri, 14 Oct 2016 16:49:43 +0200 Subject: [PATCH 1/1] wlem keys --- .../management/commands/wlem_generate_keys.py | 32 +++++++++++++++++++ wtem/management/commands/wtem_send_keys.py | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 wtem/management/commands/wlem_generate_keys.py 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]) -- 2.20.1