This repository has been archived on 2026-10-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
nikolark 7bba5770e8 Moves create member to separate resource.
* Adds CORS support

Tests are failing
2013-11-24 01:52:29 +01:00

20 lines
635 B
Python

import string
import random
from django.utils.text import slugify
def random_string(max_length=15):
return u''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(max_length))
def generate_username(data, max_length=15):
username = u""
# 1. join first and last name
username = u"{}{}".format(
slugify(data.get('first_name', u'')),
slugify(data.get('last_name', u'')))
if not username:
# 2. if no first and last, generate random
# TODO set flag so that unspecified username can be cheched later
username = random_string(max_length)
return username