From: yomguy Date: Tue, 10 Jul 2012 13:25:18 +0000 (+0200) Subject: fix init passwd script X-Git-Tag: 0.7-dev~19^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=12b99614fd562909ca45a2eab3a76def6944cc52;p=teleforma.git fix init passwd script --- diff --git a/teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py b/teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py index 658e26c4..70da1ca1 100644 --- a/teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py +++ b/teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py @@ -21,25 +21,25 @@ class Command(BaseCommand): subject_template = 'postman/email_user_subject_init.txt' language_code = 'fr_FR' - def init_password_email(self, user, profile): + def init_password_email(self, user): site = Site.objects.get_current() ctx_dict = {'site': site, 'organization': settings.TELEMETA_ORGANIZATION, 'usr': user} subject = render_to_string(self.subject_template, ctx_dict) subject = ''.join(subject.splitlines()) message = render_to_string(self.message_template, ctx_dict) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False) - profile.init_password = True - profile.save() def handle(self, *args, **options): -# users = User.objects.all() + users = User.objects.all() translation.activate(self.language_code) - users = User.objects.filter(is_staff=True) +# users = User.objects.filter(is_staff=True) for user in users: profile, c = Profile.objects.get_or_create(user=user) - if profile: - profile.init_password = False - if not profile.init_password and user.is_active: - self.init_password_email(user, profile) + student = user.student.all() + if profile and student and user.is_active: + if not profile.init_password : + self.init_password_email(user) + profile.init_password = True + profile.save() print user.username