From b15ca021db41f0db1f9f93116cec321426fb05c7 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 10 Jan 2024 08:48:08 +0100 Subject: [PATCH] close accounts regarding period account closing date --- .../commands/teleforma-deactivate-students.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/teleforma/management/commands/teleforma-deactivate-students.py b/teleforma/management/commands/teleforma-deactivate-students.py index a366a0a5..3e0c48c0 100644 --- a/teleforma/management/commands/teleforma-deactivate-students.py +++ b/teleforma/management/commands/teleforma-deactivate-students.py @@ -26,7 +26,7 @@ class Logger: class Command(BaseCommand): - help = "Deactivate student user for a given period" + help = "Deactivate students accounts" language_code = 'fr_FR' def add_arguments(self, parser): @@ -34,18 +34,20 @@ class Command(BaseCommand): def handle(self, *args, **options): log_file = args[-1] - period_name = args[-2] logger = Logger(log_file) logger.logger.info('########### Processing #############') - period = Period.objects.get(name=period_name) + today = datetime.date.today() students = Student.objects.filter(period=period) translation.activate(self.language_code) for student in students: if student.user: - if student.is_subscribed and student.confirmation_sent and student.user.email and student.user.is_active: + if student.is_subscribed and student.confirmation_sent and \ + student.user.email and student.user.is_active and \ + student.period.date_close_accounts <= today: + student.user.is_active = False student.user.save() logger.logger.info('deactivated : ' + student.user.username) -- 2.39.5