]> git.parisson.com Git - teleforma.git/commitdiff
add a remind message to all users for the end of the e-learning session
authorGuillaume Pellerin <yomguy@parisson.com>
Fri, 6 Dec 2013 20:36:17 +0000 (21:36 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Fri, 6 Dec 2013 20:36:17 +0000 (21:36 +0100)
teleforma/management/commands/teleforma-message-all-seminar-users.py [new file with mode: 0644]
teleforma/templates/teleforma/messages/seminar_remind.txt [new file with mode: 0644]
teleforma/templates/teleforma/messages/seminar_remind_subject.txt [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-message-all-seminar-users.py b/teleforma/management/commands/teleforma-message-all-seminar-users.py
new file mode 100644 (file)
index 0000000..fd1cd3b
--- /dev/null
@@ -0,0 +1,69 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.contrib.auth.forms import PasswordResetForm
+from django.contrib.auth.tokens import default_token_generator
+from django.template.defaultfilters import slugify
+from django.template.loader import render_to_string
+from django.core.mail import send_mail, mail_admins
+from django.utils import translation
+from telemeta.models import *
+from telemeta.util.unaccent import unaccent
+from teleforma.models import *
+import logging
+
+from postman.models import *
+from postman.utils import email_visitor, notify_user
+
+
+
+class Command(BaseCommand):
+    help = "Broadcast a message to all users thanks to their subscription"
+    message_template = 'teleforma/messages/seminar_remind.txt'
+    subject_template = 'teleforma/messages/seminar_remind_subject.txt'
+    language_code = 'fr_FR'
+
+    def handle(self, *args, **options):
+        users = User.objects.all()
+        translation.activate(self.language_code)
+        sender_email = settings.DEFAULT_FROM_EMAIL
+        sender = User.objects.get(email=sender_email)
+
+        for user in users:
+            profile, c = Profile.objects.get_or_create(user=user)
+            auditor = user.auditor.all()
+            if auditor and profile and user.is_active and user.email:
+                seminars = auditor.seminars.all()
+                    for seminar in seminars:
+
+                        organization = seminar.course.department.name
+                        site = Site.objects.get_current()
+                        path = reverse('teleforma-seminar-detail', kwargs={'pk':seminar.id})
+                        gender = auditor[0].get_gender_display()
+
+                        if seminar.sub_title:
+                            title = seminar.sub_title + ' : ' + seminar.title
+                        else:
+                        
+                        context['gender'] = gender
+                        context['first_name'] = user.first_name
+                        context['last_name'] = user.last_name
+                        context['rank'] = answer.question.rank
+                        context['site'] = site
+                        context['path'] = path
+                        context['title'] = title
+                        context['organization'] = organization
+                        context['date'] = seminar.expiry_date
+                        
+                        text = render_to_string(self.message_template, context)
+                        subject = render_to_string(self.subject_template, context)
+                        subject = '%s : %s' % (seminar.title, subject)
+
+                        mess = Message(sender=sender, recipient=user, subject=subject[:119], body=text)
+                        mess.moderation_status = 'a'
+                        #mess.save()
+                        #notify_user(mess, 'acceptance')
+                        
+                        print user.username, seminar.title
+
diff --git a/teleforma/templates/teleforma/messages/seminar_remind.txt b/teleforma/templates/teleforma/messages/seminar_remind.txt
new file mode 100644 (file)
index 0000000..86ba63f
--- /dev/null
@@ -0,0 +1,11 @@
+{% load i18n %}{% autoescape off %}{% blocktrans %}{{ gender }}{% endblocktrans %} {{ last_name }},
+
+votre abonnement au séminaire e-learning "{{ title }}" arrive à expiration le {{ date }}.
+
+Nous vous rappelons que vous devez achever votre formation avant cette date.
+
+De plus, si vous souhaitez conserver les supports pédagogiques écrits de votre formation (compte-rendu écrit et recueil(s) de documents d'actualité), nous vous rappelons que ceux-ci sont entièrement téléchargeables sur la plate-forme e-learning de Pro-Barreau jusqu'au {{ date }} minuit."
+
+{% blocktrans %} 
+The team of the {{ organization }} thank you for your confidence and we remain at your disposal for further information.
+{% endblocktrans %}{% endautoescape %}
diff --git a/teleforma/templates/teleforma/messages/seminar_remind_subject.txt b/teleforma/templates/teleforma/messages/seminar_remind_subject.txt
new file mode 100644 (file)
index 0000000..8a04997
--- /dev/null
@@ -0,0 +1 @@
+Arrivée à expiration de votre abonnement