wlem keys
authorJan Szejko <janek37@gmail.com>
Fri, 14 Oct 2016 14:49:43 +0000 (16:49 +0200)
committerJan Szejko <janek37@gmail.com>
Fri, 14 Oct 2016 14:50:10 +0000 (16:50 +0200)
wtem/management/commands/wlem_generate_keys.py [new file with mode: 0644]
wtem/management/commands/wtem_send_keys.py

diff --git a/wtem/management/commands/wlem_generate_keys.py b/wtem/management/commands/wlem_generate_keys.py
new file mode 100644 (file)
index 0000000..3fbf107
--- /dev/null
@@ -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))
index 213f992..96511fb 100644 (file)
@@ -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])