]> git.parisson.com Git - teleforma.git/commitdiff
Add deactivate command
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 22 Dec 2016 18:07:31 +0000 (19:07 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 22 Dec 2016 18:07:31 +0000 (19:07 +0100)
teleforma/management/commands/teleforma-students-deactivate.py [new file with mode: 0644]
teleforma/templates/teleforma/course_media.html

diff --git a/teleforma/management/commands/teleforma-students-deactivate.py b/teleforma/management/commands/teleforma-students-deactivate.py
new file mode 100644 (file)
index 0000000..bf93034
--- /dev/null
@@ -0,0 +1,50 @@
+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 import *
+
+
+class Logger:
+    """A logging object"""
+
+    def __init__(self, file):
+        self.logger = logging.getLogger('teleforma')
+        self.hdlr = logging.FileHandler(file)
+        self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
+        self.hdlr.setFormatter(self.formatter)
+        self.logger.addHandler(self.hdlr)
+        self.logger.setLevel(logging.INFO)
+
+
+class Command(BaseCommand):
+    help = "Activate all user account for subscribed students"
+
+    def handle(self, *args, **options):
+        period_name = args[-2]
+        log_file = args[-1]
+        logger = Logger(log_file)
+        logger.logger.info('########### Processing #############')
+        users = User.objects.all()
+        period = Period.objects.get(name=period_name)
+
+        for user in users:
+            students = user.student.all()
+            if students:
+                student = students[0]
+                if student.is_subscribed and user.is_active and student.period == period:
+                    user.is_active = False
+                    user.save()
+                    logger.logger.info('init : ' + user.username)
+
+        logger.logger.info('############## Done #################')
index 154cb5309d9ef2f35a7c668c085366c9971afcac..39a0a1a4ae7e2e1904d0151f432864c3ae58c596 100644 (file)
 <link href="{{STATIC_URL}}teleforma/video-js/video-js.css" rel="stylesheet">
 {% endif %}
 
-<script type="text/javascript">
-$(document).ready(function(){
-    InitChatWindow("{% url jqchat_ajax room.id %}", null);
-    $('#my_video_1').bind('contextmenu',function() { return false; });
-    });
-</script>
+    <script type="text/javascript">
+    $(document).ready(function(){
+        InitChatWindow("{% url jqchat_ajax room.id %}", null);
+        $('#my_video_1').bind('contextmenu',function() { return false; });
+        });
+    </script>
 
 {% if user.is_staff %}
 <script type="text/javascript">