OpenSlides/openslides/participant/api.py

47 lines
1.0 KiB
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.
2012-04-25 22:29:19 +02:00
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
2011-07-31 10:46:29 +02:00
:license: GNU GPL, see LICENSE for more details.
"""
2012-04-25 22:29:19 +02:00
2011-09-03 17:17:29 +02:00
from random import choice
import string
2011-07-31 10:46:29 +02:00
from django.contrib.auth.models import User
2011-07-31 10:46:29 +02:00
2011-09-03 17:17:29 +02:00
def gen_password():
"""
generates a random passwort.
"""
2011-09-03 17:17:29 +02:00
chars = string.letters + string.digits
newpassword = ''
for i in range(8):
newpassword += choice(chars)
return newpassword
2011-07-31 10:46:29 +02:00
def gen_username(first_name, last_name):
"""
generates the username for new users.
"""
2011-07-31 10:46:29 +02:00
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