コード例 #1
0
ファイル: __init__.py プロジェクト: DrMeers/django-old
def get_default_username(check_db=True):
    """
    Try to determine the current system user's username to use as a default.

    :param check_db: If ``True``, requires that the username does not match an
        existing ``auth.User`` (otherwise returns an empty string).
    :returns: The username, or an empty string if no username can be
        determined.
    """
    from django.contrib.auth.management.commands.createsuperuser import (
        RE_VALID_USERNAME)
    default_username = get_system_username()
    try:
        default_username = unicodedata.normalize('NFKD', default_username)\
            .encode('ascii', 'ignore').replace(' ', '').lower()
    except UnicodeDecodeError:
        return ''
    if not RE_VALID_USERNAME.match(default_username):
        return ''
    # Don't return the default username if it is already taken.
    if check_db and default_username:
        try:
            User.objects.get(username=default_username)
        except User.DoesNotExist:
            pass
        else:
            return ''
    return default_username
コード例 #2
0
def get_default_username(check_db=True):
    """
    Try to determine the current system user's username to use as a default.

    :param check_db: If ``True``, requires that the username does not match an
        existing ``auth.User`` (otherwise returns an empty string).
    :returns: The username, or an empty string if no username can be
        determined.
    """
    from django.contrib.auth.management.commands.createsuperuser import (
        RE_VALID_USERNAME)
    default_username = get_system_username()
    try:
        default_username = unicodedata.normalize('NFKD', default_username)\
            .encode('ascii', 'ignore').replace(' ', '').lower()
    except UnicodeDecodeError:
        return ''
    if not RE_VALID_USERNAME.match(default_username):
        return ''
    # Don't return the default username if it is already taken.
    if check_db and default_username:
        try:
            User.objects.get(username=default_username)
        except User.DoesNotExist:
            pass
        else:
            return ''
    return default_username
コード例 #3
0
ファイル: create_user.py プロジェクト: 02strich/EvaP
def is_valid_username(username):
    if not RE_VALID_USERNAME.match(username):
        raise exceptions.ValidationError(_("Error: That username is invalid. Use only letters, digits and underscores.\n"))
    
    try:
        User.objects.get(username__iexact=username)
    except User.DoesNotExist:
        pass
    else:
        raise exceptions.ValidationError(_("Error: That username is already taken.\n"))
コード例 #4
0
def is_valid_username(username):
    if not RE_VALID_USERNAME.match(username):
        raise exceptions.ValidationError(
            _("Error: That username is invalid. Use only letters, digits and underscores.\n"
              ))

    try:
        User.objects.get(username__iexact=username)
    except User.DoesNotExist:
        pass
    else:
        raise exceptions.ValidationError(
            _("Error: That username is already taken.\n"))