set first password by users with None or '' firstpassword

This commit is contained in:
Oskar Hahn 2011-09-05 09:08:00 +02:00
parent f4f7aa4e57
commit c6259d83bb

View File

@ -11,6 +11,7 @@
""" """
from django.db import models from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -54,7 +55,7 @@ class Profile(models.Model):
) )
def set_first_user_passwords(): def set_first_user_passwords():
for user in Profile.objects.filter(firstpassword=''): for user in Profile.objects.filter(Q(firstpassword='') | Q(firstpassword__isnull=True)):
user.firstpassword = gen_password() user.firstpassword = gen_password()
user.user.set_password(user.firstpassword) user.user.set_password(user.firstpassword)
user.user.save() user.user.save()