class Command(BaseCommand):
- help = "Deactivate student user for a given period"
+ help = "Deactivate students accounts"
language_code = 'fr_FR'
def add_arguments(self, parser):
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)