OpenSlides/openslides/participant/api.py

30 lines
739 B
Python
Raw Normal View History

2011-07-31 10:46:29 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.participant.api
~~~~~~~~~~~~~~~~~~~~~~~~~~
Useful functions for the participant app.
:copyright: 2011 by the OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from django.contrib.auth.models import User
2011-07-31 10:46:29 +02:00
def gen_username(first_name, last_name):
testname = "%s%s" % (first_name, last_name)
try:
User.objects.get(username=testname)
except User.DoesNotExist:
return testname
i = 0
while True:
i += 1
testname = "%s%s%s" % (first_name, last_name, i)
try:
User.objects.get(username=testname)
except User.DoesNotExist:
return testname