Fixed username

This commit is contained in:
Oskar Hahn 2013-04-19 16:45:18 +02:00
parent 38558e9b03
commit 6b558907c0
2 changed files with 7 additions and 4 deletions

View File

@ -35,7 +35,7 @@ def gen_username(first_name, last_name):
"""
generates the username for new users.
"""
testname = "%s %s" % (first_name.strip(), last_name.strip())
testname = "%s_%s" % (first_name.strip(), last_name.strip())
try:
User.objects.get(username=testname)
except User.DoesNotExist:
@ -43,7 +43,7 @@ def gen_username(first_name, last_name):
i = 0
while True:
i += 1
testname = "%s %s %s" % (first_name, last_name, i)
testname = "%s_%s_%s" % (first_name, last_name, i)
try:
User.objects.get(username=testname)
except User.DoesNotExist:

View File

@ -62,9 +62,12 @@ class UserUpdateForm(UserCreateForm):
Raises a validation error, if a non-superuser user edits himself
and removes the last group containing the permission to manage participants.
"""
# TODO: Check this in clean_groups
if self.request.user == self.instance and not self.instance.is_superuser:
protected_perm = Permission.objects.get(content_type=ContentType.objects.get(app_label='participant', model='user'),
codename='can_manage_participant')
protected_perm = Permission.objects.get(
content_type=ContentType.objects.get(app_label='participant',
model='user'),
codename='can_manage_participant')
if not self.cleaned_data['groups'].filter(permissions__in=[protected_perm]).exists():
error_msg = _('You can not remove the last group containing the permission to manage participants.')
messages.error(self.request, error_msg)