From 4fb4691f14e4cecb8e896d282be23816dae8c011 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Mon, 5 Sep 2011 22:26:19 +0200 Subject: [PATCH] Added counter and message for password generation. --- openslides/participant/models.py | 3 +++ openslides/participant/views.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 83665c344..e7ec19a31 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -55,8 +55,11 @@ class Profile(models.Model): ) def set_first_user_passwords(): + count = 0 for user in Profile.objects.filter(Q(firstpassword='') | Q(firstpassword__isnull=True)): + count = count + 1 user.firstpassword = gen_password() user.user.set_password(user.firstpassword) user.user.save() user.save() + return count \ No newline at end of file diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 35cacb025..d72c8e70e 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -19,7 +19,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import SetPasswordForm from django.contrib import messages 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.api import gen_username @@ -287,7 +287,11 @@ def user_import(request): @permission_required('participant.can_manage_participant') 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'))