From: Guillaume Pellerin Date: Wed, 10 Jan 2024 07:48:08 +0000 (+0100) Subject: close accounts regarding period account closing date X-Git-Tag: 2.9.0~50 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=b15ca021db41f0db1f9f93116cec321426fb05c7;p=teleforma.git close accounts regarding period account closing date --- 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)