import datetime
from postman.utils import notify_user
from teleforma.context_processors import seminar_validated
-
+import sys
class Command(BaseCommand):
help = """Send a reminder to all users when their subscripted seminars
expire before a given number of days"""
- args = ['days',]
message_template = 'teleforma/messages/seminar_remind.txt'
subject_template = 'teleforma/messages/seminar_remind_subject.txt'
language_code = 'fr_FR'
+ def add_arguments(self, parser):
+ parser.add_argument('days', type=int,
+ help='number of days')
+ parser.add_argument('logfile', type=str,
+ help='log file to use')
+
+ def log(self, msg):
+ today = datetime.datetime.now()
+ print(today.strftime('%Y-%m-%d %H:%M'), msg)
+
def handle(self, *args, **kwargs):
- days = int(args[-1])
+ days = kwargs['days']
+ logpath = kwargs['logfile']
+ sys.stdout = open(logpath, 'a', encoding='utf-8')
+
+ self.log("Starting run")
+
users = User.objects.all()
translation.activate(self.language_code)
sender_email = settings.DEFAULT_FROM_EMAIL
sender = User.objects.get(email=sender_email)
today = datetime.datetime.now()
+
for user in users:
auditor = user.auditor.all()
professor = user.professor.all()
enough_time = get_seminar_delta(user, seminar)
validated = completed and enough_time > 0
if delta.days < days and delta.days >= 0 and not validated:
+ self.log("Seminar %s is about to expire" % seminar)
seminars.append(seminar)
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)
+ self.log("Sending mail to %s about %d seminars" % (user, len(seminars)))
+
# mess = Message(sender=sender, recipient='yoanl@pilotsystems.net', subject=subject[:119], body=text)
mess.moderation_status = 'a'
mess.save()
class Command(BaseCommand):
help = "Credit time to students connected to a Big Blue Button webclass"
- args = "duration"
+ def add_arguments(self, parser):
+ parser.add_argument('duration', type=int,
+ help='duration in seconds')
+ parser.add_argument('logfile', type=str,
+ help='log file to use')
+
+
def handle(self, *args, **options):
- if len(args) != 1 or not args[0].isdigit():
- print(("Syntax: %s %s <duration in seconds>" % (sys.argv[0],
- sys.argv[1])))
- sys.exit(1)
+ duration = options['duration']
+ logpath = options['logfile']
+ sys.stdout = open(logpath, 'a', encoding='utf-8')
- duration = int(args[0])
end = datetime.datetime.now()
start = end - datetime.timedelta(seconds = duration)
print(("=== Starting at %s" % end.strftime('%Y-%m-%d %H:%M:%S')))
return
meetings = as_list(meetings["meeting"])
- print(("=== Starting at %s" % end.strftime('%Y-%m-%d %H:%M:%S')))
+ print(("=== Starting at %s (with duration %d)" % (end.strftime('%Y-%m-%d %H:%M:%S'), duration)))
done = set()