Added counter and message for password generation.
This commit is contained in:
parent
7eac8cda5d
commit
4fb4691f14
@ -55,8 +55,11 @@ class Profile(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def set_first_user_passwords():
|
def set_first_user_passwords():
|
||||||
|
count = 0
|
||||||
for user in Profile.objects.filter(Q(firstpassword='') | Q(firstpassword__isnull=True)):
|
for user in Profile.objects.filter(Q(firstpassword='') | Q(firstpassword__isnull=True)):
|
||||||
|
count = count + 1
|
||||||
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()
|
||||||
user.save()
|
user.save()
|
||||||
|
return count
|
@ -19,7 +19,7 @@ from django.contrib.auth.decorators import login_required
|
|||||||
from django.contrib.auth.forms import SetPasswordForm
|
from django.contrib.auth.forms import SetPasswordForm
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _, ungettext
|
||||||
|
|
||||||
from participant.models import Profile, set_first_user_passwords
|
from participant.models import Profile, set_first_user_passwords
|
||||||
from participant.api import gen_username
|
from participant.api import gen_username
|
||||||
@ -287,7 +287,11 @@ def user_import(request):
|
|||||||
|
|
||||||
@permission_required('participant.can_manage_participant')
|
@permission_required('participant.can_manage_participant')
|
||||||
def gen_passwords(request):
|
def gen_passwords(request):
|
||||||
set_first_user_passwords()
|
count = set_first_user_passwords()
|
||||||
|
if count:
|
||||||
|
messages.success(request, ungettext('%s Password was successfully generated.', '%s Passwords were successfully generated.', count ) % count)
|
||||||
|
else:
|
||||||
|
messages.info(request, _('There are no participants which need a first time password. No passwords generated.') )
|
||||||
return redirect(reverse('user_overview'))
|
return redirect(reverse('user_overview'))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user